Skip to content

Commit 81436f4

Browse files
committed
config text editor
initial work on text editor show proper error in footer add open config editor to keybind proper theming update command bar updated CHANGELOG better dark theme.
1 parent 8d498e2 commit 81436f4

18 files changed

Lines changed: 690 additions & 49 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
Added:
44

5+
- Config editor pane for editing the config file in-app
56
- Improved legibility of the returned values of `MONITOR` list (`/monitor L`)
67

78
Fixed:

Cargo.lock

Lines changed: 83 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ iced = { workspace = true, features = [
8484
"x11",
8585
"crisp",
8686
"web-colors",
87+
"highlighter",
8788
] }
8889
percent-encoding = { workspace = true }
8990

assets/fontello/config.json

100644100755
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,12 @@
211211
"css": "eraser",
212212
"code": 61741,
213213
"src": "fontawesome"
214+
},
215+
{
216+
"uid": "6533bdc16ab201eb3f3b27ce989cab33",
217+
"css": "folder-open-empty",
218+
"code": 61717,
219+
"src": "fontawesome"
214220
}
215221
]
216222
}

data/src/buffer.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ pub enum Internal {
3737
Highlights,
3838
#[strum(serialize = "Channel Discovery")]
3939
ChannelDiscovery(Option<Server>),
40+
#[strum(serialize = "Config Editor")]
41+
ConfigEditor,
4042
}
4143

4244
impl Buffer {
@@ -114,6 +116,7 @@ impl Internal {
114116
Self::Logs,
115117
Self::Highlights,
116118
Self::ChannelDiscovery(None),
119+
Self::ConfigEditor,
117120
];
118121

119122
pub fn key(&self) -> String {
@@ -122,6 +125,7 @@ impl Internal {
122125
Internal::Logs => "logs",
123126
Internal::Highlights => "highlights",
124127
Internal::ChannelDiscovery(_) => "channel-discovery",
128+
Internal::ConfigEditor => "config-editor",
125129
}
126130
.to_string()
127131
}

data/src/config.rs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ impl Config {
528528
.map_err(|e| Error::LoadConfigFile(e.to_string()))?;
529529

530530
let config = toml::Deserializer::parse(content.as_ref())
531-
.map_err(|e| Error::Parse(e.to_string()))?;
531+
.map_err(|e| Error::Parse(ParseError::new(&content, &e)))?;
532532

533533
let Configuration {
534534
theme,
@@ -559,7 +559,7 @@ impl Config {
559559
} = serde_ignored::deserialize(config, |ignored| {
560560
log::warn!("[config.toml] Ignoring unknown setting: {ignored}");
561561
})
562-
.map_err(|e| Error::Parse(e.to_string()))?;
562+
.map_err(|e| Error::Parse(ParseError::new(&content, &e)))?;
563563

564564
let servers = ServerMap::new(
565565
servers,
@@ -787,6 +787,32 @@ pub fn random_nickname_with_seed<R: Rng>(rng: &mut R) -> String {
787787
rand_nick
788788
}
789789

790+
#[derive(Debug, Clone)]
791+
pub struct ParseError {
792+
/// Short description of the problem, e.g. `invalid basic string`.
793+
pub message: String,
794+
/// Full rendered error, including a snippet of the offending TOML.
795+
pub details: String,
796+
/// Zero-indexed line of the parse error in the config file.
797+
pub line: Option<usize>,
798+
}
799+
800+
impl ParseError {
801+
fn new(content: &str, error: &toml::de::Error) -> Self {
802+
let line = error.span().map(|span| {
803+
content[..span.start.min(content.len())]
804+
.matches('\n')
805+
.count()
806+
});
807+
808+
Self {
809+
message: error.message().to_owned(),
810+
details: error.to_string(),
811+
line,
812+
}
813+
}
814+
}
815+
790816
#[derive(Debug, Error, Clone)]
791817
pub enum Error {
792818
#[error("config could not be read: {0}")]
@@ -795,8 +821,8 @@ pub enum Error {
795821
ExecutePasswordCommand(String),
796822
#[error("{0}")]
797823
Io(String),
798-
#[error("{0}")]
799-
Parse(String),
824+
#[error("{}", .0.details)]
825+
Parse(ParseError),
800826
#[error("UTF8 parsing error: {0}")]
801827
StrUtf8Error(#[from] str::Utf8Error),
802828
#[error("UTF8 parsing error: {0}")]

data/src/config/keys.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub struct Keyboard {
3737
pub cycle_previous_unread_buffer: KeyBinds,
3838
pub mark_as_read: KeyBinds,
3939
pub quit_application: KeyBinds,
40+
pub open_config_editor: KeyBinds,
4041
pub open_config_file: KeyBinds,
4142
}
4243

@@ -75,6 +76,7 @@ impl Default for Keyboard {
7576
KeyBind::cycle_previous_unread_buffer().into(),
7677
mark_as_read: KeyBind::mark_as_read().into(),
7778
quit_application: KeyBind::quit_application().into(),
79+
open_config_editor: KeyBind::open_config_editor().into(),
7880
open_config_file: KeyBind::open_config_file().into(),
7981
}
8082
}
@@ -128,6 +130,7 @@ impl Keyboard {
128130
);
129131
push(&self.mark_as_read, MarkAsRead);
130132
push(&self.quit_application, QuitApplication);
133+
push(&self.open_config_editor, OpenConfigEditor);
131134
push(&self.open_config_file, OpenConfigFile);
132135

133136
shortcuts

data/src/history.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ impl Kind {
132132
}
133133
Buffer::Internal(buffer::Internal::FileTransfers) => None,
134134
Buffer::Internal(buffer::Internal::ChannelDiscovery(_)) => None,
135+
Buffer::Internal(buffer::Internal::ConfigEditor) => None,
135136
}
136137
}
137138
}

data/src/shortcut.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ pub enum Command {
107107
CycleNextUnreadBuffer,
108108
CyclePreviousUnreadBuffer,
109109
MarkAsRead,
110+
OpenConfigEditor,
110111
OpenConfigFile,
111112
}
112113

@@ -295,9 +296,10 @@ impl KeyBind {
295296
#[cfg(not(target_os = "linux"))]
296297
default!(quit_application);
297298
#[cfg(target_os = "macos")]
298-
default!(open_config_file, ",", COMMAND);
299+
default!(open_config_editor, ",", COMMAND);
299300
#[cfg(not(target_os = "macos"))]
300-
default!(open_config_file, ",", CTRL);
301+
default!(open_config_editor, ",", CTRL);
302+
default!(open_config_file);
301303
}
302304

303305
impl From<(keyboard::Key, keyboard::Modifiers)> for KeyBind {

docs/configuration/keyboard.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,5 @@ Each shortcut accepts either a single keybind string or an array of keybind stri
5151
| `theme_editor` | Toggle Theme Editor Window | <kbd>⌘</kbd> + <kbd>t</kbd> | <kbd>ctrl</kbd> + <kbd>t</kbd> |
5252
| `highlights` | Toggle Highlights Window | <kbd>⌘</kbd> + <kbd>i</kbd> | <kbd>ctrl</kbd> + <kbd>i</kbd> |
5353
| `quit_application` | Quit Halloy | None | None |
54-
| `open_config_file` | Open settings file in system editor | <kbd>⌘</kbd> + <kbd>,</kbd> | <kbd>ctrl</kbd> + <kbd>,</kbd>None |
54+
| `open_config_editor` | Toggle Config Editor Buffer | <kbd>⌘</kbd> + <kbd>,</kbd> | <kbd>ctrl</kbd> + <kbd>,</kbd> |
55+
| `open_config_file` | Open settings file in system editor | None | None |

0 commit comments

Comments
 (0)