diff options
| -rw-r--r-- | src/icon.txt | 11 | ||||
| -rw-r--r-- | src/lib.rs | 39 | ||||
| -rw-r--r-- | src/run/builtin.rs | 22 | ||||
| -rw-r--r-- | src/run/mod.rs | 1 |
4 files changed, 71 insertions, 2 deletions
diff --git a/src/icon.txt b/src/icon.txt new file mode 100644 index 0000000..2eedd0c --- /dev/null +++ b/src/icon.txt @@ -0,0 +1,11 @@ +#### # #### # # +# # # # # # +# # # # # # +#### # #### #### +------------------- +# # # # # +# # # # # # # +# # # # # # +# # # ############# +# # +####### # # # @@ -8,7 +8,7 @@ use std::collections::HashMap; use std::ffi::OsStr; use std::fs::{self, File}; -use std::io::{self, Read, Write}; +use std::io::{self, BufRead, Read, Write}; use std::os::unix::ffi::OsStrExt; use std::os::unix::io::AsRawFd; use std::path::Path; @@ -35,6 +35,7 @@ pub mod rw; pub mod serialization; pub mod wait; +use libc::BS0; use linebuf::LineBuf; use raw::*; @@ -545,3 +546,39 @@ pub fn event_loop() { session.lock().unwrap().raw_disable(); } + +pub fn icon() -> BString { + const DATA: &[u8] = include_bytes!("icon.txt"); + const COLOR0: &[u8] = b"\x1b[100m"; + const COLOR1: &[u8] = b"\x1b[47m"; + const COLOR_RESET: &[u8] = b"\x1b[0m"; + let mut color = COLOR0; + let mut buf = BString::new(); + + for line in DATA.split(|x| *x == b'\n') { + if line.starts_with(b"-") { + color = COLOR1; + continue; + } + + let mut colored = false; + for &b in line { + if b == b'#' { + if !colored { + buf.push_all(color); + colored = true; + } + } else if colored { + buf.push_all(COLOR_RESET); + colored = false; + } + buf.push_all(b" "); + } + if colored { + buf.push_all(COLOR_RESET); + } + buf.push_all(b"\r\n"); + } + + buf +} diff --git a/src/run/builtin.rs b/src/run/builtin.rs index bd82e27..9f3ff62 100644 --- a/src/run/builtin.rs +++ b/src/run/builtin.rs @@ -839,7 +839,7 @@ impl Builtin for ct { b"screen_clear" => { drop(se); Session::screen_clear(session); - }, + } b"history_previous" => se.history_up(), b"history_next" => se.history_down(), b"prompt_del_left" => se.del_left(), @@ -945,3 +945,23 @@ impl Builtin for Here { Ok(()) } } + +#[derive(Copy, Clone)] +pub struct logo; + +impl Builtin for logo { + fn name(&self) -> &str { + "logo" + } + + fn io( + &self, + _session: Arc<Mutex<Session>>, + _args: &[BString], + _stdin: &mut dyn Read, + stdout: &mut dyn Write, + ) -> Result { + stdout.write_all(&crate::icon())?; + Ok(()) + } +} diff --git a/src/run/mod.rs b/src/run/mod.rs index ddac394..a5fd69a 100644 --- a/src/run/mod.rs +++ b/src/run/mod.rs @@ -710,6 +710,7 @@ const BUILTINS: &[&'static dyn BuiltinClone] = &[ &builtin::Break, &builtin::Continue, &builtin::Here, + &builtin::logo, ]; pub fn builtin_map() -> HashMap<BString, &'static dyn BuiltinClone> { |
