1use std::sync::Arc;
9
10use super::widget::Widget;
11
12#[derive(Debug, Clone, Copy, Default)]
14pub struct ThingyFlags {
15 pub disabled: bool,
17 pub immortal: bool,
19}
20
21#[derive(Debug, Clone)]
23pub struct Thingy {
24 pub name: String,
26 pub flags: ThingyFlags,
28 pub rc: i32,
30 pub widget: Option<Arc<Widget>>,
32}
33
34impl Thingy {
35 pub fn new(name: &str) -> Self {
37 Thingy {
38 name: name.to_string(),
39 flags: ThingyFlags::default(),
40 rc: 1,
41 widget: None,
42 }
43 }
44
45 pub fn builtin(name: &str) -> Self {
47 let widget = Widget::builtin(name);
48 Thingy {
49 name: name.to_string(),
50 flags: ThingyFlags {
51 disabled: false,
52 immortal: true,
53 },
54 rc: 1,
55 widget: Some(Arc::new(widget)),
56 }
57 }
58
59 pub fn user_defined(name: &str, func_name: &str) -> Self {
61 let widget = Widget::user_defined(name, func_name);
62 Thingy {
63 name: name.to_string(),
64 flags: ThingyFlags::default(),
65 rc: 1,
66 widget: Some(Arc::new(widget)),
67 }
68 }
69
70 pub fn is(&self, name: &str) -> bool {
72 self.name == name
73 }
74
75 pub fn is_thingy(&self, name: &str) -> bool {
78 self.name == name || self.name == format!(".{}", name)
79 }
80}
81
82pub mod names {
84 pub const ACCEPT_LINE: &str = "accept-line";
86 pub const SEND_BREAK: &str = "send-break";
88 pub const SELF_INSERT: &str = "self-insert";
90 pub const DELETE_CHAR_OR_LIST: &str = "delete-char-or-list";
92 pub const BACKWARD_DELETE_CHAR: &str = "backward-delete-char";
94 pub const BACKWARD_CHAR: &str = "backward-char";
96 pub const FORWARD_CHAR: &str = "forward-char";
98 pub const BEGINNING_OF_LINE: &str = "beginning-of-line";
100 pub const END_OF_LINE: &str = "end-of-line";
102 pub const BACKWARD_WORD: &str = "backward-word";
104 pub const FORWARD_WORD: &str = "forward-word";
106 pub const KILL_LINE: &str = "kill-line";
108 pub const KILL_WHOLE_LINE: &str = "kill-whole-line";
110 pub const KILL_WORD: &str = "kill-word";
112 pub const BACKWARD_KILL_WORD: &str = "backward-kill-word";
114 pub const YANK: &str = "yank";
116 pub const UNDO: &str = "undo";
118 pub const REDO: &str = "redo";
120 pub const CLEAR_SCREEN: &str = "clear-screen";
122 pub const EXPAND_OR_COMPLETE: &str = "expand-or-complete";
124 pub const HISTORY_INCREMENTAL_SEARCH_BACKWARD: &str = "history-incremental-search-backward";
126 pub const HISTORY_INCREMENTAL_SEARCH_FORWARD: &str = "history-incremental-search-forward";
128 pub const UP_LINE_OR_HISTORY: &str = "up-line-or-history";
130 pub const DOWN_LINE_OR_HISTORY: &str = "down-line-or-history";
132 pub const TRANSPOSE_CHARS: &str = "transpose-chars";
134 pub const DELETE_CHAR: &str = "delete-char";
136 pub const VI_CMD_MODE: &str = "vi-cmd-mode";
138 pub const VI_INSERT: &str = "vi-insert";
140}