Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into use_dbus
Browse files Browse the repository at this point in the history
  • Loading branch information
osa1 committed Apr 6, 2024
2 parents 90e4fcf + c6d380c commit c753c71
Show file tree
Hide file tree
Showing 20 changed files with 183 additions and 239 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Unreleased
# 2024/01/01: 0.12.0

Thanks to @nate-sys and @jubalh for contributing to this release.

## New features

- New TUI text attributes `italic` and `strikethrough` added to the config file
parser. These can be combined with the existing `bold` and `underline`
attributes. (#409, #404)
Expand All @@ -12,11 +14,15 @@ Thanks to @nate-sys and @jubalh for contributing to this release.
command: quit
```
(#403, #410)
## Bug fixes and other improvements
- Default config updated with better comments, color config for join/part
messages. (#412)
- `/join` command errors now print usage help once instead of twice.
- `/join` command errors now print usage help once instead of twice. (c512887)
- Fix showing timestamp of the next message or activity after a `/clear`.
(#417)
- Fix a crash when the config file is deleted before a `/reload`. (3ea5678)

# 2023/07/16: 0.11.0

Expand Down
42 changes: 21 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ cargo install --git https://github.com/osa1/tiny
If you have an older version installed, add `--force` to the command you're
using.

Arch Linux users can install tiny from [AUR].
Arch Linux users can install the latest [stable] and [development] versions
of tiny through the AUR.

[AUR]: https://aur.archlinux.org/packages/tiny-irc-client-git/
[stable]: https://aur.archlinux.org/packages/tiny/
[development]: https://aur.archlinux.org/packages/tiny-git/

tiny is tested on Linux and OSX.

Expand Down
2 changes: 1 addition & 1 deletion crates/libtiny_client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ async fn main_loop(
tokio::task::spawn_local(async move {
let mut rcv_msg = ReceiverStream::new(rcv_msg);
while let Some(msg) = rcv_msg.next().await {
if let Err(io_err) = write_half.write_all(msg.as_str().as_bytes()).await {
if let Err(io_err) = write_half.write_all(msg.as_bytes()).await {
debug!("IO error when writing: {:?}", io_err);
snd_ev_clone.send(Event::IoErr(io_err)).await.unwrap();
return;
Expand Down
2 changes: 1 addition & 1 deletion crates/libtiny_client/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(clippy::zero_prefixed_literal)]
#![allow(clippy::get_first, clippy::zero_prefixed_literal)]

use crate::{utils, SASLAuth};
use crate::{Cmd, Event, ServerInfo};
Expand Down
25 changes: 13 additions & 12 deletions crates/libtiny_common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,22 +236,23 @@ pub enum TabStyle {
Highlight,
}

/// UI events
/// UI events.
#[derive(Debug)]
pub enum Event {
Abort {
msg: Option<String>,
},
Msg {
msg: String,
source: MsgSource,
},
/// User wants to quit.
Quit { msg: Option<String> },

/// A message was sent.
Msg { msg: String, source: MsgSource },

/// A multi-line message was sent.
///
/// This can be done by pasting, or via the editor command (`C-x` by default).
Lines {
lines: Vec<String>,
source: MsgSource,
},
Cmd {
cmd: String,
source: MsgSource,
},

/// A command was submitted. `cmd` won't have an initial '/'.
Cmd { cmd: String, source: MsgSource },
}
2 changes: 1 addition & 1 deletion crates/libtiny_tui/examples/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ fn handle_input_ev(ui: &TUI, ev: Event, abort: &mut mpsc::Sender<()>) {
ui.set_nick(SERV, new_nick);
}
}
Abort { .. } => {
Quit { .. } => {
abort.try_send(()).unwrap();
}
Msg { .. } | Lines { .. } => {}
Expand Down
2 changes: 1 addition & 1 deletion crates/libtiny_tui/examples/tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@ fn handle_input_ev(ui: &TUI, ev: Event) {
}
}
}
Abort { .. } | Msg { .. } | Lines { .. } => {}
Quit { .. } | Msg { .. } | Lines { .. } => {}
}
}
104 changes: 43 additions & 61 deletions crates/libtiny_tui/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@ use libtiny_common::{ChanName, ChanNameRef};
use serde::de::{self, Deserializer, MapAccess, Visitor};
use serde::Deserialize;
use std::collections::HashMap;
use std::fs::File;
use std::io::Read;
use std::path::Path;
use std::str::FromStr;

pub use termbox_simple::*;
use termbox_simple::*;

use crate::key_map::KeyMap;
use crate::notifier::Notifier;
Expand Down Expand Up @@ -75,28 +72,7 @@ pub enum Chan {
}

impl Chan {
pub fn name(&self) -> &ChanNameRef {
match self {
Chan::Name(name) => name,
Chan::WithConfig { name, .. } => name,
}
.as_ref()
}
}

fn deser_chan_name<'de, D>(d: D) -> Result<ChanName, D::Error>
where
D: Deserializer<'de>,
{
let name: String = serde::de::Deserialize::deserialize(d)?;
Ok(ChanName::new(name))
}

// `FromStr` implementation used when parsing channel names in commands (not in config file).
impl FromStr for Chan {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
pub fn from_cmd_args(s: &str) -> Result<Chan, String> {
// Make sure channel starts with '#'
let s = if !s.starts_with('#') {
format!("#{}", s)
Expand All @@ -107,7 +83,7 @@ impl FromStr for Chan {
match s.split_once(' ') {
// with args
Some((name, args)) => {
let config = TabConfig::from_str(args)?;
let config = TabConfig::from_cmd_args(args)?;
Ok(Chan::WithConfig {
name: ChanName::new(name.to_string()),
config,
Expand All @@ -117,6 +93,22 @@ impl FromStr for Chan {
None => Ok(Chan::Name(ChanName::new(s))),
}
}

pub fn name(&self) -> &ChanNameRef {
match self {
Chan::Name(name) => name,
Chan::WithConfig { name, .. } => name,
}
.as_ref()
}
}

fn deser_chan_name<'de, D>(d: D) -> Result<ChanName, D::Error>
where
D: Deserializer<'de>,
{
let name: String = serde::de::Deserialize::deserialize(d)?;
Ok(ChanName::new(name))
}

/// Map of TabConfigs by tab names
Expand Down Expand Up @@ -207,32 +199,7 @@ pub struct TabConfig {
}

impl TabConfig {
pub fn user_tab_defaults() -> TabConfig {
TabConfig {
ignore: Some(false),
notify: Some(Notifier::Messages),
}
}

pub(crate) fn or_use(&self, config: &TabConfig) -> TabConfig {
TabConfig {
ignore: self.ignore.or(config.ignore),
notify: self.notify.or(config.notify),
}
}

pub(crate) fn toggle_ignore(&mut self) -> bool {
let ignore = self.ignore.get_or_insert(false);
*ignore = !&*ignore;
*ignore
}
}

// `FromStr` implementation used when parsing channel names in commands (not in config file).
impl FromStr for TabConfig {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
pub(crate) fn from_cmd_args(s: &str) -> Result<TabConfig, String> {
let mut config = TabConfig::default();
let mut words = s.trim().split(' ').map(str::trim);

Expand All @@ -245,7 +212,7 @@ impl FromStr for TabConfig {
"-ignore" => config.ignore = Some(true),
"-notify" => match words.next() {
Some(notify_setting) => {
config.notify = Some(Notifier::from_str(notify_setting)?)
config.notify = Some(Notifier::from_cmd_args(notify_setting)?)
}
None => return Err("-notify parameter missing".to_string()),
},
Expand All @@ -255,6 +222,19 @@ impl FromStr for TabConfig {

Ok(config)
}

pub(crate) fn or_use(&self, config: &TabConfig) -> TabConfig {
TabConfig {
ignore: self.ignore.or(config.ignore),
notify: self.notify.or(config.notify),
}
}

pub(crate) fn toggle_ignore(&mut self) -> bool {
let ignore = self.ignore.get_or_insert(false);
*ignore = !&*ignore;
*ignore
}
}

fn default_max_nick_length() -> usize {
Expand Down Expand Up @@ -510,12 +490,14 @@ impl<'de> Deserialize<'de> for Style {
}

pub(crate) fn parse_config(config_path: &Path) -> Result<Config, serde_yaml::Error> {
let contents = {
let mut str = String::new();
let mut file = File::open(config_path).unwrap();
file.read_to_string(&mut str).unwrap();
str
};

// tiny creates a config file with the defaults when it can't find one, but the config file can
// be deleted before a `/reload`.
let contents = std::fs::read_to_string(config_path).map_err(|err| {
de::Error::custom(format!(
"Can't read config file '{}': {}",
config_path.to_string_lossy(),
err
))
})?;
serde_yaml::from_str(&contents)
}
Loading

0 comments on commit c753c71

Please sign in to comment.