Use hashbrown::HashMap

This commit is contained in:
Alexandre Bury 2019-03-16 16:16:30 -07:00
parent 3a0b49088b
commit 19ad7b6cc3
7 changed files with 45 additions and 49 deletions

View File

@ -32,6 +32,7 @@ term_size = { version = "0.3.1", optional = true }
crossbeam-channel = "0.3.6"
lazy_static = "1.2.0"
chrono = "0.4.6"
hashbrown = "0.1.8"
[dependencies.num]
default-features = false

View File

@ -5,7 +5,7 @@
use bear_lib_terminal;
use std::collections::HashSet;
use hashbrown::HashSet;
use self::bear_lib_terminal::geometry::Size;
use self::bear_lib_terminal::terminal::{
@ -17,7 +17,6 @@ use crate::backend;
use crate::event::{Event, Key, MouseButton, MouseEvent};
use crate::theme::{BaseColor, Color, ColorPair, Effect};
use crate::vec::Vec2;
use unicode_width::UnicodeWidthStr;
enum ColorRole {
Foreground,

View File

@ -3,7 +3,7 @@
//! Requires either of `ncurses-backend` or `pancurses-backend`.
#![cfg(any(feature = "ncurses-backend", feature = "pancurses-backend"))]
use std::collections::HashMap;
use hashbrown::HashMap;
use crate::event::{Event, Key};
use crate::theme::{BaseColor, Color, ColorPair};

View File

@ -1,10 +1,9 @@
//! Ncurses-specific backend.
use log::{debug, warn};
use maplit::hashmap;
use ncurses;
use hashbrown::HashMap;
use std::cell::{Cell, RefCell};
use std::collections::HashMap;
use std::ffi::CString;
use std::fs::File;
use std::io;
@ -456,50 +455,47 @@ where
fn initialize_keymap() -> HashMap<i32, Event> {
// 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
-1 => Event::Refresh,
// Values under 256 are chars and control values
// 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
//
// 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),
map.insert(410, Event::WindowResize);
410 => Event::WindowResize,
ncurses::KEY_B2 => Event::Key(Key::NumpadCenter),
ncurses::KEY_DC => Event::Key(Key::Del),
ncurses::KEY_IC => Event::Key(Key::Ins),
ncurses::KEY_BTAB => Event::Shift(Key::Tab),
ncurses::KEY_SLEFT => Event::Shift(Key::Left),
ncurses::KEY_SRIGHT => Event::Shift(Key::Right),
ncurses::KEY_LEFT => Event::Key(Key::Left),
ncurses::KEY_RIGHT => Event::Key(Key::Right),
ncurses::KEY_UP => Event::Key(Key::Up),
ncurses::KEY_DOWN => Event::Key(Key::Down),
ncurses::KEY_SR => Event::Shift(Key::Up),
ncurses::KEY_SF => Event::Shift(Key::Down),
ncurses::KEY_PPAGE => Event::Key(Key::PageUp),
ncurses::KEY_NPAGE => Event::Key(Key::PageDown),
ncurses::KEY_HOME => Event::Key(Key::Home),
ncurses::KEY_END => Event::Key(Key::End),
ncurses::KEY_SHOME => Event::Shift(Key::Home),
ncurses::KEY_SEND => Event::Shift(Key::End),
ncurses::KEY_SDC => Event::Shift(Key::Del),
ncurses::KEY_SNEXT => Event::Shift(Key::PageDown),
ncurses::KEY_SPREVIOUS => Event::Shift(Key::PageUp),
};
map.insert(ncurses::KEY_B2, Event::Key(Key::NumpadCenter));
map.insert(ncurses::KEY_DC, Event::Key(Key::Del));
map.insert(ncurses::KEY_IC, Event::Key(Key::Ins));
map.insert(ncurses::KEY_BTAB, Event::Shift(Key::Tab));
map.insert(ncurses::KEY_SLEFT, Event::Shift(Key::Left));
map.insert(ncurses::KEY_SRIGHT, Event::Shift(Key::Right));
map.insert(ncurses::KEY_LEFT, Event::Key(Key::Left));
map.insert(ncurses::KEY_RIGHT, Event::Key(Key::Right));
map.insert(ncurses::KEY_UP, Event::Key(Key::Up));
map.insert(ncurses::KEY_DOWN, Event::Key(Key::Down));
map.insert(ncurses::KEY_SR, Event::Shift(Key::Up));
map.insert(ncurses::KEY_SF, Event::Shift(Key::Down));
map.insert(ncurses::KEY_PPAGE, Event::Key(Key::PageUp));
map.insert(ncurses::KEY_NPAGE, Event::Key(Key::PageDown));
map.insert(ncurses::KEY_HOME, Event::Key(Key::Home));
map.insert(ncurses::KEY_END, Event::Key(Key::End));
map.insert(ncurses::KEY_SHOME, Event::Shift(Key::Home));
map.insert(ncurses::KEY_SEND, Event::Shift(Key::End));
map.insert(ncurses::KEY_SDC, Event::Shift(Key::Del));
map.insert(ncurses::KEY_SNEXT, Event::Shift(Key::PageDown));
map.insert(ncurses::KEY_SPREVIOUS, Event::Shift(Key::PageUp));
// Then add some dynamic ones

View File

@ -2,8 +2,8 @@
use log::{debug, warn};
use pancurses;
use hashbrown::HashMap;
use std::cell::{Cell, RefCell};
use std::collections::HashMap;
use std::io::{stdout, Write};
use crate::backend;

View File

@ -1,5 +1,5 @@
use hashbrown::HashMap;
use std::any::Any;
use std::collections::HashMap;
use std::path::Path;
use std::time::Duration;

View File

@ -3,7 +3,7 @@ use enum_map::{enum_map, Enum, EnumMap};
use log::warn;
use toml;
use std::collections::HashMap;
use hashbrown::HashMap;
use std::ops::{Index, IndexMut};
/// Color configuration for the application.