mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Use hashbrown::HashMap
This commit is contained in:
parent
3a0b49088b
commit
19ad7b6cc3
@ -32,6 +32,7 @@ term_size = { version = "0.3.1", optional = true }
|
|||||||
crossbeam-channel = "0.3.6"
|
crossbeam-channel = "0.3.6"
|
||||||
lazy_static = "1.2.0"
|
lazy_static = "1.2.0"
|
||||||
chrono = "0.4.6"
|
chrono = "0.4.6"
|
||||||
|
hashbrown = "0.1.8"
|
||||||
|
|
||||||
[dependencies.num]
|
[dependencies.num]
|
||||||
default-features = false
|
default-features = false
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
use bear_lib_terminal;
|
use bear_lib_terminal;
|
||||||
|
|
||||||
use std::collections::HashSet;
|
use hashbrown::HashSet;
|
||||||
|
|
||||||
use self::bear_lib_terminal::geometry::Size;
|
use self::bear_lib_terminal::geometry::Size;
|
||||||
use self::bear_lib_terminal::terminal::{
|
use self::bear_lib_terminal::terminal::{
|
||||||
@ -17,7 +17,6 @@ use crate::backend;
|
|||||||
use crate::event::{Event, Key, MouseButton, MouseEvent};
|
use crate::event::{Event, Key, MouseButton, MouseEvent};
|
||||||
use crate::theme::{BaseColor, Color, ColorPair, Effect};
|
use crate::theme::{BaseColor, Color, ColorPair, Effect};
|
||||||
use crate::vec::Vec2;
|
use crate::vec::Vec2;
|
||||||
use unicode_width::UnicodeWidthStr;
|
|
||||||
|
|
||||||
enum ColorRole {
|
enum ColorRole {
|
||||||
Foreground,
|
Foreground,
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
//! Requires either of `ncurses-backend` or `pancurses-backend`.
|
//! Requires either of `ncurses-backend` or `pancurses-backend`.
|
||||||
#![cfg(any(feature = "ncurses-backend", feature = "pancurses-backend"))]
|
#![cfg(any(feature = "ncurses-backend", feature = "pancurses-backend"))]
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use hashbrown::HashMap;
|
||||||
|
|
||||||
use crate::event::{Event, Key};
|
use crate::event::{Event, Key};
|
||||||
use crate::theme::{BaseColor, Color, ColorPair};
|
use crate::theme::{BaseColor, Color, ColorPair};
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
//! Ncurses-specific backend.
|
//! Ncurses-specific backend.
|
||||||
use log::{debug, warn};
|
use log::{debug, warn};
|
||||||
use maplit::hashmap;
|
|
||||||
use ncurses;
|
use ncurses;
|
||||||
|
|
||||||
|
use hashbrown::HashMap;
|
||||||
use std::cell::{Cell, RefCell};
|
use std::cell::{Cell, RefCell};
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io;
|
use std::io;
|
||||||
@ -456,50 +455,47 @@ where
|
|||||||
|
|
||||||
fn initialize_keymap() -> HashMap<i32, Event> {
|
fn initialize_keymap() -> HashMap<i32, Event> {
|
||||||
// First, define the static mappings.
|
// First, define the static mappings.
|
||||||
let mut map = hashmap! {
|
let mut map = HashMap::new();
|
||||||
|
// Value sent by ncurses when nothing happens
|
||||||
|
map.insert(-1, Event::Refresh);
|
||||||
|
|
||||||
// Value sent by ncurses when nothing happens
|
// Values under 256 are chars and control values
|
||||||
-1 => Event::Refresh,
|
// Tab is '\t'
|
||||||
|
map.insert(9, Event::Key(Key::Tab));
|
||||||
|
// Treat '\n' and the numpad Enter the same
|
||||||
|
map.insert(10, Event::Key(Key::Enter));
|
||||||
|
map.insert(ncurses::KEY_ENTER, Event::Key(Key::Enter));
|
||||||
|
// This is the escape key when pressed by itself.
|
||||||
|
// When used for control sequences,
|
||||||
|
// it should have been caught earlier.
|
||||||
|
map.insert(27, Event::Key(Key::Esc));
|
||||||
|
// `Backspace` sends 127, but Ctrl-H sends `Backspace`
|
||||||
|
map.insert(127, Event::Key(Key::Backspace));
|
||||||
|
map.insert(ncurses::KEY_BACKSPACE, Event::Key(Key::Backspace));
|
||||||
|
|
||||||
// Values under 256 are chars and control values
|
map.insert(410, Event::WindowResize);
|
||||||
//
|
|
||||||
// Tab is '\t'
|
|
||||||
9 => Event::Key(Key::Tab),
|
|
||||||
// Treat '\n' and the numpad Enter the same
|
|
||||||
10 => Event::Key(Key::Enter),
|
|
||||||
ncurses::KEY_ENTER => Event::Key(Key::Enter),
|
|
||||||
// This is the escape key when pressed by itself.
|
|
||||||
// When used for control sequences,
|
|
||||||
// it should have been caught earlier.
|
|
||||||
27 => Event::Key(Key::Esc),
|
|
||||||
// `Backspace` sends 127, but Ctrl-H sends `Backspace`
|
|
||||||
127 => Event::Key(Key::Backspace),
|
|
||||||
ncurses::KEY_BACKSPACE => Event::Key(Key::Backspace),
|
|
||||||
|
|
||||||
410 => Event::WindowResize,
|
map.insert(ncurses::KEY_B2, Event::Key(Key::NumpadCenter));
|
||||||
|
map.insert(ncurses::KEY_DC, Event::Key(Key::Del));
|
||||||
ncurses::KEY_B2 => Event::Key(Key::NumpadCenter),
|
map.insert(ncurses::KEY_IC, Event::Key(Key::Ins));
|
||||||
ncurses::KEY_DC => Event::Key(Key::Del),
|
map.insert(ncurses::KEY_BTAB, Event::Shift(Key::Tab));
|
||||||
ncurses::KEY_IC => Event::Key(Key::Ins),
|
map.insert(ncurses::KEY_SLEFT, Event::Shift(Key::Left));
|
||||||
ncurses::KEY_BTAB => Event::Shift(Key::Tab),
|
map.insert(ncurses::KEY_SRIGHT, Event::Shift(Key::Right));
|
||||||
ncurses::KEY_SLEFT => Event::Shift(Key::Left),
|
map.insert(ncurses::KEY_LEFT, Event::Key(Key::Left));
|
||||||
ncurses::KEY_SRIGHT => Event::Shift(Key::Right),
|
map.insert(ncurses::KEY_RIGHT, Event::Key(Key::Right));
|
||||||
ncurses::KEY_LEFT => Event::Key(Key::Left),
|
map.insert(ncurses::KEY_UP, Event::Key(Key::Up));
|
||||||
ncurses::KEY_RIGHT => Event::Key(Key::Right),
|
map.insert(ncurses::KEY_DOWN, Event::Key(Key::Down));
|
||||||
ncurses::KEY_UP => Event::Key(Key::Up),
|
map.insert(ncurses::KEY_SR, Event::Shift(Key::Up));
|
||||||
ncurses::KEY_DOWN => Event::Key(Key::Down),
|
map.insert(ncurses::KEY_SF, Event::Shift(Key::Down));
|
||||||
ncurses::KEY_SR => Event::Shift(Key::Up),
|
map.insert(ncurses::KEY_PPAGE, Event::Key(Key::PageUp));
|
||||||
ncurses::KEY_SF => Event::Shift(Key::Down),
|
map.insert(ncurses::KEY_NPAGE, Event::Key(Key::PageDown));
|
||||||
ncurses::KEY_PPAGE => Event::Key(Key::PageUp),
|
map.insert(ncurses::KEY_HOME, Event::Key(Key::Home));
|
||||||
ncurses::KEY_NPAGE => Event::Key(Key::PageDown),
|
map.insert(ncurses::KEY_END, Event::Key(Key::End));
|
||||||
ncurses::KEY_HOME => Event::Key(Key::Home),
|
map.insert(ncurses::KEY_SHOME, Event::Shift(Key::Home));
|
||||||
ncurses::KEY_END => Event::Key(Key::End),
|
map.insert(ncurses::KEY_SEND, Event::Shift(Key::End));
|
||||||
ncurses::KEY_SHOME => Event::Shift(Key::Home),
|
map.insert(ncurses::KEY_SDC, Event::Shift(Key::Del));
|
||||||
ncurses::KEY_SEND => Event::Shift(Key::End),
|
map.insert(ncurses::KEY_SNEXT, Event::Shift(Key::PageDown));
|
||||||
ncurses::KEY_SDC => Event::Shift(Key::Del),
|
map.insert(ncurses::KEY_SPREVIOUS, Event::Shift(Key::PageUp));
|
||||||
ncurses::KEY_SNEXT => Event::Shift(Key::PageDown),
|
|
||||||
ncurses::KEY_SPREVIOUS => Event::Shift(Key::PageUp),
|
|
||||||
};
|
|
||||||
|
|
||||||
// Then add some dynamic ones
|
// Then add some dynamic ones
|
||||||
|
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
use log::{debug, warn};
|
use log::{debug, warn};
|
||||||
use pancurses;
|
use pancurses;
|
||||||
|
|
||||||
|
use hashbrown::HashMap;
|
||||||
use std::cell::{Cell, RefCell};
|
use std::cell::{Cell, RefCell};
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::io::{stdout, Write};
|
use std::io::{stdout, Write};
|
||||||
|
|
||||||
use crate::backend;
|
use crate::backend;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
use hashbrown::HashMap;
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ use enum_map::{enum_map, Enum, EnumMap};
|
|||||||
use log::warn;
|
use log::warn;
|
||||||
use toml;
|
use toml;
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use hashbrown::HashMap;
|
||||||
use std::ops::{Index, IndexMut};
|
use std::ops::{Index, IndexMut};
|
||||||
|
|
||||||
/// Color configuration for the application.
|
/// Color configuration for the application.
|
||||||
|
Loading…
Reference in New Issue
Block a user