Skip to content

Commit 1dae16c

Browse files
casperstormandymandias
authored andcommitted
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 cda97c2 commit 1dae16c

20 files changed

Lines changed: 696 additions & 50 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Added:
44

55
- Internal buffers (logs, highlights, etc) can be added to sidebar
6+
- Config editor pane for editing the config file in-app
67
- Improved legibility of the returned values of `MONITOR` list (`/monitor L`)
78
- Config option (`preview.card.description_decode_html`) to decode html strings in preview card descriptions
89
- Support displaying a larger version of the card images in-app

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
@@ -92,6 +92,7 @@ iced = { workspace = true, features = [
9292
"x11",
9393
"crisp",
9494
"web-colors",
95+
"highlighter",
9596
] }
9697
percent-encoding = { workspace = true }
9798

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: 5 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
}
@@ -130,6 +134,7 @@ impl Internal {
130134
impl From<config::sidebar::InternalBuffer> for Internal {
131135
fn from(config: config::sidebar::InternalBuffer) -> Self {
132136
match config {
137+
config::sidebar::InternalBuffer::ConfigEditor => Self::ConfigEditor,
133138
config::sidebar::InternalBuffer::FileTransfers => {
134139
Self::FileTransfers
135140
}

data/src/config.rs

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

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

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

565565
keyboard.validate()?;
566566

@@ -790,6 +790,32 @@ pub fn random_nickname_with_seed<R: Rng>(rng: &mut R) -> String {
790790
rand_nick
791791
}
792792

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

data/src/config/keys.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub struct Keyboard {
4242
pub cycle_previous_unread_buffer: KeyBinds,
4343
pub mark_as_read: KeyBinds,
4444
pub quit_application: KeyBinds,
45+
pub open_config_editor: KeyBinds,
4546
pub open_config_file: KeyBinds,
4647
}
4748

@@ -80,6 +81,7 @@ impl Default for Keyboard {
8081
KeyBind::cycle_previous_unread_buffer().into(),
8182
mark_as_read: KeyBind::mark_as_read().into(),
8283
quit_application: KeyBind::quit_application().into(),
84+
open_config_editor: KeyBind::open_config_editor().into(),
8385
open_config_file: KeyBind::open_config_file().into(),
8486
}
8587
}
@@ -122,6 +124,7 @@ impl Keyboard {
122124
),
123125
(&self.mark_as_read, MarkAsRead),
124126
(&self.quit_application, QuitApplication),
127+
(&self.open_config_editor, OpenConfigEditor),
125128
(&self.open_config_file, OpenConfigFile),
126129
]
127130
}

data/src/config/sidebar.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ pub enum OrderChannelsBy {
297297
#[derive(Debug, Copy, Clone, Deserialize, PartialEq, Eq)]
298298
#[serde(rename_all = "kebab-case")]
299299
pub enum InternalBuffer {
300+
ConfigEditor,
300301
FileTransfers,
301302
ChannelDiscovery,
302303
Highlights,

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
@@ -108,6 +108,7 @@ pub enum Command {
108108
CycleNextUnreadBuffer,
109109
CyclePreviousUnreadBuffer,
110110
MarkAsRead,
111+
OpenConfigEditor,
111112
OpenConfigFile,
112113
}
113114

@@ -356,9 +357,10 @@ impl KeyBind {
356357
#[cfg(not(target_os = "linux"))]
357358
default!(quit_application);
358359
#[cfg(target_os = "macos")]
359-
default!(open_config_file, ",", COMMAND);
360+
default!(open_config_editor, ",", COMMAND);
360361
#[cfg(not(target_os = "macos"))]
361-
default!(open_config_file, ",", CTRL);
362+
default!(open_config_editor, ",", CTRL);
363+
default!(open_config_file);
362364
}
363365

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

0 commit comments

Comments
 (0)