Skip to content

Commit

Permalink
Add basic crossterm drawing to screen
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-hughes committed May 15, 2021
1 parent 0b42ef5 commit 5cf617b
Show file tree
Hide file tree
Showing 8 changed files with 968 additions and 875 deletions.
132 changes: 132 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ readme = "README.md"

[dependencies]
pancurses = "0.16.1"
crossterm = "0.19.0"
rss = "1.10.0"
rusqlite = "0.21.0"
clap = "2.33.1"
Expand Down
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ pub const EPISODE_PUBDATE_LENGTH: usize = 60;

// How many columns we need (total terminal window width) before we
// display the details panel
pub const DETAILS_PANEL_LENGTH: i32 = 135;
pub const DETAILS_PANEL_LENGTH: u16 = 135;

// How many lines will be scrolled by the big scroll,
// in relation to the rows eg: 4 = 1/4 of the screen
pub const BIG_SCROLL_AMOUNT: i32 = 4;
pub const BIG_SCROLL_AMOUNT: u16 = 4;


/// Identifies the user's selection for what to do with new episodes
Expand Down
146 changes: 27 additions & 119 deletions src/keymap.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use pancurses::Input;
use crossterm::event::KeyCode;
use std::collections::HashMap;

use crate::config::KeybindingsFromToml;
Expand Down Expand Up @@ -104,7 +104,7 @@ impl Keybindings {

/// Takes an Input object from pancurses and returns the associated
/// user action, if one exists.
pub fn get_from_input(&self, input: Input) -> Option<&UserAction> {
pub fn get_from_input(&self, input: KeyCode) -> Option<&UserAction> {
match input_to_str(input) {
Some(code) => self.0.get(&code),
None => None,
Expand Down Expand Up @@ -185,135 +185,43 @@ impl Keybindings {
/// This function is a bit ridiculous, given that 95% of keyboards
/// probably don't even have half these special keys, but at any rate...
/// they're mapped, if anyone wants them.
pub fn input_to_str(input: Input) -> Option<String> {
pub fn input_to_str(input: KeyCode) -> Option<String> {
let mut tmp = [0; 4];
let code = match input {
Input::KeyCodeYes => "CodeYes",
Input::KeyBreak => "Break",
Input::KeyDown => "Down",
Input::KeyUp => "Up",
Input::KeyLeft => "Left",
Input::KeyRight => "Right",
Input::KeyHome => "Home",
Input::KeyBackspace => "Backspace",
Input::KeyF0 => "F0",
Input::KeyF1 => "F1",
Input::KeyF2 => "F2",
Input::KeyF3 => "F3",
Input::KeyF4 => "F4",
Input::KeyF5 => "F5",
Input::KeyF6 => "F6",
Input::KeyF7 => "F7",
Input::KeyF8 => "F8",
Input::KeyF9 => "F9",
Input::KeyF10 => "F10",
Input::KeyF11 => "F11", // F11 triggers KeyResize for me
Input::KeyF12 => "F12",
Input::KeyF13 => "F13",
Input::KeyF14 => "F14",
Input::KeyF15 => "F15",
Input::KeyDL => "DL",
Input::KeyIL => "IL",
Input::KeyDC => "Del",
Input::KeyIC => "Ins",
Input::KeyEIC => "EIC",
Input::KeyClear => "Clear",
Input::KeyEOS => "EOS",
Input::KeyEOL => "EOL",
Input::KeySF => "S_Down",
Input::KeySR => "S_Up",
Input::KeyNPage => "PgDn",
Input::KeyPPage => "PgUp",
Input::KeySTab => "STab", // this doesn't appear to be Shift+Tab
Input::KeyCTab => "C_Tab",
Input::KeyCATab => "CATab",
Input::KeyEnter => "Enter",
Input::KeySReset => "SReset",
Input::KeyReset => "Reset",
Input::KeyPrint => "Print",
Input::KeyLL => "LL",
Input::KeyAbort => "Abort",
Input::KeySHelp => "SHelp",
Input::KeyLHelp => "LHelp",
Input::KeyBTab => "S_Tab", // Shift+Tab
Input::KeyBeg => "Beg",
Input::KeyCancel => "Cancel",
Input::KeyClose => "Close",
Input::KeyCommand => "Command",
Input::KeyCopy => "Copy",
Input::KeyEnd => "End",
Input::KeyExit => "Exit",
Input::KeyFind => "Find",
Input::KeyHelp => "Help",
Input::KeyMark => "Mark",
Input::KeyMessage => "Message",
Input::KeyMove => "Move",
Input::KeyNext => "Next",
Input::KeyOpen => "Open",
Input::KeyOptions => "Options",
Input::KeyPrevious => "Previous",
Input::KeyRedo => "Redo",
Input::KeyReference => "Reference",
Input::KeyRefresh => "Refresh",
Input::KeyResume => "Resume",
Input::KeyRestart => "Restart",
Input::KeySave => "Save",
Input::KeySBeg => "S_Beg",
Input::KeySCancel => "S_Cancel",
Input::KeySCommand => "S_Command",
Input::KeySCopy => "S_Copy",
Input::KeySCreate => "S_Create",
Input::KeySDC => "S_Del",
Input::KeySDL => "S_DL",
Input::KeySelect => "Select",
Input::KeySEnd => "S_End",
Input::KeySEOL => "S_EOL",
Input::KeySExit => "S_Exit",
Input::KeySFind => "S_Find",
Input::KeySHome => "S_Home",
Input::KeySIC => "S_Ins",
Input::KeySLeft => "S_Left",
Input::KeySMessage => "S_Message",
Input::KeySMove => "S_Move",
Input::KeySNext => "S_PgDn",
Input::KeySOptions => "S_Options",
Input::KeySPrevious => "S_PgUp",
Input::KeySPrint => "S_Print",
Input::KeySRedo => "S_Redo",
Input::KeySReplace => "S_Replace",
Input::KeySRight => "S_Right",
Input::KeySResume => "S_Resume",
Input::KeySSave => "S_Save",
Input::KeySSuspend => "S_Suspend",
Input::KeySUndo => "S_Undo",
Input::KeySuspend => "Suspend",
Input::KeyUndo => "Undo",
Input::KeyResize => "F11", // I'm marking this as F11 as well
Input::KeyEvent => "Event",
Input::KeyMouse => "Mouse",
Input::KeyA1 => "A1",
Input::KeyA3 => "A3",
Input::KeyB2 => "B2",
Input::KeyC1 => "C1",
Input::KeyC3 => "C3",
Input::Character(c) => {
KeyCode::Backspace => "Backspace".to_string(),
KeyCode::Enter => "Enter".to_string(),
KeyCode::Left => "Left".to_string(),
KeyCode::Right => "Right".to_string(),
KeyCode::Up => "Up".to_string(),
KeyCode::Down => "Down".to_string(),
KeyCode::Home => "Home".to_string(),
KeyCode::End => "End".to_string(),
KeyCode::PageUp => "PgUp".to_string(),
KeyCode::PageDown => "PgDn".to_string(),
KeyCode::Tab => "Tab".to_string(),
KeyCode::BackTab => "S_Tab".to_string(),
KeyCode::Delete => "Del".to_string(),
KeyCode::Insert => "Ins".to_string(),
KeyCode::Esc => "Esc".to_string(),
KeyCode::F(num) => format!("F{}", num), // Function keys
KeyCode::Char(c) => {
if c == '\u{7f}' {
"Backspace"
"Backspace".to_string()
} else if c == '\u{1b}' {
"Escape"
"Escape".to_string()
} else if c == '\n' {
"Enter"
"Enter".to_string()
} else if c == '\t' {
"Tab"
"Tab".to_string()
} else {
c.encode_utf8(&mut tmp)
c.encode_utf8(&mut tmp).to_string()
}
}
_ => "",
_ => "".to_string(),
};
if code.is_empty() {
return None;
} else {
return Some(code.to_string());
return Some(code);
}
}
Loading

0 comments on commit 5cf617b

Please sign in to comment.