Skip to content

Commit

Permalink
Vi: Move terminal handling to vi
Browse files Browse the repository at this point in the history
We now have a new IPC interface, twili::IPipe, representing a pipe on
which we can read and write data.

Vi now implements the font rendering and other associated logic with
terminal handling. It does so by implementing the IPipe interface.

We have lost the ability to print colors in the terminal. This will be
reinstated in a future commit, which will add ansi escape codes.
  • Loading branch information
roblabla committed Oct 17, 2019
1 parent ab9998c commit cf1a9d6
Show file tree
Hide file tree
Showing 14 changed files with 553 additions and 287 deletions.
5 changes: 4 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
34 changes: 34 additions & 0 deletions ipcdefs/twili.id
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# The Twili Service is responsible for providing the stdin/stdout/stderr pipes
# to the various subprocesses. It is freely taken from the [twili] switch
# process.
interface sunrise_libuser::twili::ITwiliService is twili {
# Recover the stdin/stdout/stderr pipes for the current process.
#
# If none were registered, returns an error.
[0] open_pipes(pid) -> (
object<sunrise_libuser::twili::IPipe> stdin,
object<sunrise_libuser::twili::IPipe> stdout,
object<sunrise_libuser::twili::IPipe> stderr);
}

# The Twili Manager is responsible for registering a process' pipes. The PM
# should connect to this service and register pipes before starting a process.
interface sunrise_libuser::twili::ITwiliManagerService is twili:m {
# Registers the pipe of a remote process.
[0] register_pipes(pid,
object<sunrise_libuser::twili::IPipe> stdin,
object<sunrise_libuser::twili::IPipe> stdout,
object<sunrise_libuser::twili::IPipe> stderr);
}

# IPC Pipe Object
interface sunrise_libuser::twili::IPipe {
# Reads data from the pipe.
#
# May block if there isn't enough data to return.
[0] read() -> (u64 size_read, array<u8, 0x6> out_buf);
# Writes data to the other side of the pipe.
#
# May block if the other side isn't reading fast enough.
[1] write(array<u8, 0x5> out_buf);
}
10 changes: 9 additions & 1 deletion ipcdefs/vi.id
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,17 @@ interface sunrise_libuser::vi::ViInterface is vi: {
[0] create_buffer(handle<copy, shared_memory> framebuffer, i32 top, i32 left, u32 width, u32 height) -> object<sunrise_libuser::vi::IBuffer>;
# Gets the screen resolution.
[1] get_screen_resolution() -> (u32 width, u32 height);
# Gets the height of the font used for rendering a terminal line.
[2] get_font_height() -> u32 height;
# Create a terminal.
#
# This creates a terminal at the given coordinates, with the given
# height.
#
# It is allowed to place the framebuffer outside the field of view.
[3] create_terminal(handle<copy, shared_memory> framebuffer, i32 top, i32 left, u32 width, u32 height) -> object<sunrise_libuser::twili::IPipe>;
}


# IPC Window object
interface sunrise_libuser::vi::IBuffer {
# Blit the buffer to the framebuffer.
Expand Down
1 change: 0 additions & 1 deletion libuser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ spin = "0.5"
sunrise-libutils = { path = "../libutils" }
sunrise-libkern = { path = "../libkern" }
failure = { version = "0.1", default-features = false }
font-rs = { git = "https://github.com/SunriseOS/font-rs", default-features = false }
log = "0.4"
lazy_static = "1.3"
futures-preview = { version = "=0.3.0-alpha.16", default-features = false, features = ["nightly", "alloc"] }
Expand Down
7 changes: 4 additions & 3 deletions libuser/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ use std::path::{Path, PathBuf};
use swipc_gen::generate_ipc;

/// Array containing all module names and id path to use with swipc-gen.
const MODULES_ARRAY: [(&str, &str); 8] =
[
const MODULES_ARRAY: &[(&str, &str)] =
&[
("sm", "../../ipcdefs/sm.id"),
("vi", "../../ipcdefs/vi.id"),
("ahci", "../../ipcdefs/ahci.id"),
("time", "../../ipcdefs/time.id"),
("fs", "../../ipcdefs/filesystem.id"),
("keyboard", "../../ipcdefs/keyboard.id"),
("ldr", "../../ipcdefs/loader.id"),
("twili", "../../ipcdefs/twili.id"),
("example", "../../ipcdefs/example.id"),
];

Expand All @@ -35,7 +36,7 @@ fn main() {
let root = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap_or_else(|_| ".".into()));


for module in &MODULES_ARRAY {
for module in MODULES_ARRAY {
let module_name = module.0;
let module_path = module.1;

Expand Down
20 changes: 18 additions & 2 deletions libuser/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ pub enum Error {
Pm(PmError, Backtrace),
/// Service Manager error.
Sm(SmError, Backtrace),
//Vi(ViError, Backtrace),
/// Vi Error
Vi(ViError, Backtrace),
/// Internal Libuser error.
Libuser(LibuserError, Backtrace),
/// Ahci driver error.
Expand Down Expand Up @@ -99,7 +100,7 @@ impl Error {
Error::Loader(err, ..) => err.0 << 9 | Module::Loader.0,
Error::Pm(err, ..) => err.0 << 9 | Module::Pm.0,
Error::Sm(err, ..) => err.0 << 9 | Module::Sm.0,
//Error::Vi(err, ..) => err.0 << 9 | Module::Vi.0,
Error::Vi(err, ..) => err.0 << 9 | Module::Vi.0,
Error::Libuser(err, ..) => err.0 << 9 | Module::Libuser.0,
Error::Ahci(err, ..) => err.0 << 9 | Module::Ahci.0,
Error::Time(err, ..) => err.0 << 9 | Module::Time.0,
Expand Down Expand Up @@ -366,3 +367,18 @@ impl From<HidError> for Error {
Error::Hid(error, Backtrace::new())
}
}

enum_with_val! {
/// Vi driver errors.
#[derive(PartialEq, Eq, Clone, Copy)]
pub struct ViError(u32) {
/// The given string is not UTF-8.
InvalidUtf8 = 1,
}
}

impl From<ViError> for Error {
fn from(error: ViError) -> Self {
Error::Vi(error, Backtrace::new())
}
}
3 changes: 2 additions & 1 deletion libuser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@ pub mod futures;
//pub mod keyboard {}
//#[gen_ipc(path = "../../ipcdefs/loader.id", prefix = "sunrise_libuser")]
//pub mod ldr {}
//#[gen_ipc(path = "../../ipcdefs/twili.id", prefix = "sunrise_libuser")]
//pub mod twili {}
//#[gen_ipc(path = "../../ipcdefs/example.id", prefix = "sunrise_libuser")]
//pub mod example {}
include!(concat!(env!("OUT_DIR"), "/ipc_code.rs"));


pub mod error;
pub mod allocator;
pub mod terminal;
Expand Down
Loading

0 comments on commit cf1a9d6

Please sign in to comment.