Skip to content

Commit

Permalink
Merge pull request #654 from squidowl/disable-away
Browse files Browse the repository at this point in the history
  • Loading branch information
casperstorm authored Nov 14, 2024
2 parents 5745688 + eb80cfa commit fb64e33
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 74 deletions.
16 changes: 10 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# Unreleased

Added:
- New configuration options
- Ability to disable dimming of away usernames. See [buffer configuartion](https://halloy.squidowl.org/configuration/buffer/away.html).

# 2024.14 (2024-10-29)

Fixed:
- CPU spiking due to memory leak in upstream crate.

# 2024.13 (2024-10-27)

Added:
Expand All @@ -20,7 +24,7 @@ Added:
- Ability to define a shell command for loading a NICKSERV password. See [configuration](https://halloy.squidowl.org/configuration/servers/index.html#nick_password_command)
- Ability to define a shell command for loading a SASL password. See [configuration](https://halloy.squidowl.org/configuration/servers/sasl/plain.html)
- Show/hide sidebar button to view logs. See [configuration](https://halloy.squidowl.org/configuration/sidebar/buttons.html#logs)
- Ability to align nicknames above messages. See [configuration](https://halloy.squidowl.org/configuration/buffer/nickname.html#alignment).
- Ability to align nicknames above messages. See [configuration](https://halloy.squidowl.org/configuration/buffer/nickname.html#alignment).

Fixed:

Expand Down Expand Up @@ -75,7 +79,7 @@ Fixed:
- Messages with multiple targets are correctly recorded into multiple buffers (and/or multiple times into the same buffer) client-side.
- Messages sent with a STATUSMSG prefix are recorded and indicated in the corresponding channel.
- Ability to position the sidebar at the top, bottom, right, or left. See [configuration](https://halloy.squidowl.org/configuration/sidebar/index.html#position).
- `/mode` requires too many parameters for certain commands.
- `/mode` requires too many parameters for certain commands.

Changed:

Expand All @@ -84,7 +88,7 @@ Changed:
- Unread indicator has changed from a boolean value to a enum. See [configuration](https://halloy.squidowl.org/configuration/sidebar/index.html#unread_indicators).
- Renamed `sidebar.default_action` to `sidebar.buffer_action`.
- Auto-completing (with tab) a nickname at the beginning of the input line will append ': ' (colon space). Otherwise, a space is appended to the completion.

Removed:

- Removed `hex` configuration option for server messages and nicknames.
Expand All @@ -96,7 +100,7 @@ Removed:

Added:

- Small icon in sidemenu when a new release is available
- Small icon in sidemenu when a new release is available
- Enable support for IRCv3 `chghost`, `account-notify`, and `extended-join`

Removed:
Expand Down Expand Up @@ -145,7 +149,7 @@ Added:
- User information added to context menu
- Support for IRCv3 `CAP NEW` and `CAP DEL` subcommands
- Enable support for IRCv3 `multi-prefix`, `message-tags`, `WHOX`, and `UTF8ONLY`
- Dynamic commands and tooltips added to command auto-completion via `ISUPPORT`
- Dynamic commands and tooltips added to command auto-completion via `ISUPPORT`
- Added support for `socks5` proxy configuration (see [proxy configuration](https://halloy.squidowl.org/configuration/proxy.html))
- Added support for `http` proxy configuration (see [proxy configuration](https://halloy.squidowl.org/configuration/proxy.html))

Expand Down
5 changes: 3 additions & 2 deletions book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- [Get in touch](get-in-touch.md)

# Guides

- [Connect with soju](guides/connect-with-soju.md)
- [Connect with ZNC](guides/connect-with-znc.md)
- [Portable mode](guides/portable-mode.md)
Expand All @@ -20,6 +20,7 @@

- [Configuration](configuration/README.md)
- [Buffer](configuration/buffer/README.md)
- [Away](configuration/buffer/away.md)
- [Channel](configuration/buffer/channel/README.md)
- [Nicklist](configuration/buffer/channel/nicklist.md)
- [Message](configuration/buffer/channel/message.md)
Expand Down Expand Up @@ -55,4 +56,4 @@
- [Community](configuration/themes/community.md)
- [Tooltips](configuration/tooltips.md)
- [URL Schemes](url-schemes.md)
- [Commands](commands.md)
- [Commands](commands.md)
17 changes: 17 additions & 0 deletions book/src/configuration/buffer/away.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# `[buffer.away]`

Customize away behaviour.

**Example**

```toml
[buffer.away]
appearance = "dimmed"
```

## `appearance`
Controls the appearance of away nicknames in buffers.

- **type**: string
- **values**: `"dimmed"`, `"solid"`
- **default**: `"dimmed"`
4 changes: 4 additions & 0 deletions data/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ use core::fmt;

use serde::{Deserialize, Serialize};

pub use self::away::Away;

pub mod away;

use crate::user::Nick;
use crate::{channel, config, message, Server};

Expand Down
21 changes: 21 additions & 0 deletions data/src/buffer/away.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use serde::Deserialize;

#[derive(Debug, Clone, Copy, Default, Deserialize)]
pub struct Away {
#[serde(default)]
pub appearance: Appearance,
}

impl Away {
pub fn should_dim_nickname(&self, is_user_away: bool) -> bool {
is_user_away && matches!(self.appearance, Appearance::Dimmed)
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum Appearance {
#[default]
Dimmed,
Solid,
}
4 changes: 3 additions & 1 deletion data/src/config/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ use serde::Deserialize;

use super::Channel;
use crate::{
buffer::{Nickname, StatusMessagePrefix, TextInput, Timestamp},
buffer::{Away, Nickname, StatusMessagePrefix, TextInput, Timestamp},
message::source,
};

#[derive(Debug, Clone, Deserialize, Default)]
pub struct Buffer {
#[serde(default)]
pub away: Away,
#[serde(default)]
pub timestamp: Timestamp,
#[serde(default)]
Expand Down
13 changes: 3 additions & 10 deletions data/src/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use irc::proto;
use itertools::sorted;
use serde::{Deserialize, Serialize};

use crate::{appearance::theme::Colors, buffer, config::buffer::UsernameFormat, mode};
use crate::{config::buffer::UsernameFormat, mode};

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(into = "String")]
Expand Down Expand Up @@ -155,15 +155,8 @@ impl From<Nick> for User {
}

impl User {
pub fn nick_color(&self, colors: &Colors, kind: buffer::Color) -> NickColor {
let color = colors.buffer.nickname;
match kind {
buffer::Color::Solid => NickColor { seed: None, color },
buffer::Color::Unique => NickColor {
seed: Some(self.nickname().as_ref().to_string()),
color,
},
}
pub fn seed(&self) -> &str {
self.as_str()
}

pub fn display(&self, with_access_levels: bool) -> String {
Expand Down
43 changes: 40 additions & 3 deletions src/appearance/theme/selectable_text.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use data::{message, user::NickColor};
use data::{message, Config, User};

use crate::widget::{
selectable_rich_text,
Expand Down Expand Up @@ -82,8 +82,45 @@ pub fn server(theme: &Theme, server: Option<&message::source::Server>) -> Style
}
}

pub fn nickname(theme: &Theme, nick_color: NickColor, away: bool) -> Style {
let color = text::nickname(theme, nick_color, away).color;
pub fn nicklist_nickname(theme: &Theme, config: &Config, user: &User) -> Style {
nickname_style(
theme,
config.buffer.channel.nicklist.color,
user,
config.buffer.away.should_dim_nickname(user.is_away()),
)
}

pub fn nickname(theme: &Theme, config: &Config, user: &User) -> Style {
nickname_style(
theme,
config.buffer.channel.message.nickname_color,
user,
config.buffer.away.should_dim_nickname(user.is_away()),
)
}

pub fn topic_nickname(theme: &Theme, config: &Config, user: &User) -> Style {
nickname_style(
theme,
config.buffer.channel.message.nickname_color,
user,
false,
)
}

fn nickname_style(
theme: &Theme,
kind: data::buffer::Color,
user: &User,
should_dim_nickname: bool,
) -> Style {
let seed = match kind {
data::buffer::Color::Solid => None,
data::buffer::Color::Unique => Some(user.seed()),
};

let color = text::nickname(theme, seed, should_dim_nickname).color;

Style {
color,
Expand Down
16 changes: 6 additions & 10 deletions src/appearance/theme/text.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use data::{
appearance::theme::{alpha_color, randomize_color},
user::NickColor,
};
use data::appearance::theme::{alpha_color, randomize_color};
use iced::{
widget::text::{Catalog, Style, StyleFn},
Color,
Expand Down Expand Up @@ -85,15 +82,14 @@ pub fn unread_indicator(theme: &Theme) -> Style {
}
}

pub fn nickname(theme: &Theme, nick_color: NickColor, away: bool) -> Style {
let NickColor { color, seed } = nick_color;

pub fn nickname(theme: &Theme, seed: Option<&str>, should_dim_nickname: bool) -> Style {
let color = theme.colors().buffer.nickname;
let calculate_alpha_color = |color: Color| -> Color {
alpha_color(0.15, 0.61, theme.colors().buffer.background, color)
};

let Some(seed) = seed else {
let color = if away {
let color = if should_dim_nickname {
calculate_alpha_color(color)
} else {
color
Expand All @@ -102,8 +98,8 @@ pub fn nickname(theme: &Theme, nick_color: NickColor, away: bool) -> Style {
return Style { color: Some(color) };
};

let randomized_color = randomize_color(color, &seed);
let color = if away {
let randomized_color = randomize_color(color, seed);
let color = if should_dim_nickname {
calculate_alpha_color(randomized_color)
} else {
randomized_color
Expand Down
22 changes: 7 additions & 15 deletions src/buffer/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ pub fn view<'a>(
|prefixes| {
let text = selectable_text(format!(
"{} ",
config.buffer.status_message_prefix.brackets.format(String::from_iter(prefixes))
config
.buffer
.status_message_prefix
.brackets
.format(String::from_iter(prefixes))
))
.style(theme::selectable_text::tertiary);

Expand Down Expand Up @@ -101,13 +105,7 @@ pub fn view<'a>(
.brackets
.format(user.display(with_access_levels)),
)
.style(|theme| {
theme::selectable_text::nickname(
theme,
user.nick_color(theme.colors(), config.buffer.nickname.color),
user.is_away(),
)
});
.style(|theme| theme::selectable_text::nickname(theme, config, user));

if let Some(width) = max_nick_width {
text = text
Expand Down Expand Up @@ -462,13 +460,7 @@ mod nick_list {

let content = column(users.iter().map(|user| {
let content = selectable_text(user.display(nicklist_config.show_access_levels))
.style(|theme| {
theme::selectable_text::nickname(
theme,
user.nick_color(theme.colors(), nicklist_config.color),
user.is_away(),
)
})
.style(|theme| theme::selectable_text::nicklist_nickname(theme, config, user))
.horizontal_alignment(match nicklist_config.alignment {
config::channel::Alignment::Left => alignment::Horizontal::Left,
config::channel::Alignment::Right => alignment::Horizontal::Right,
Expand Down
8 changes: 1 addition & 7 deletions src/buffer/channel/topic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,7 @@ pub fn view<'a>(
let user = if let Some(user) = users.iter().find(|user| user.nickname() == nick) {
user_context::view(
selectable_text(user.display(config.buffer.channel.nicklist.show_access_levels))
.style(|theme| {
theme::selectable_text::nickname(
theme,
user.nick_color(theme.colors(), config.buffer.nickname.color),
false,
)
}),
.style(|theme| theme::selectable_text::topic_nickname(theme, config, user)),
server,
Some(channel),
user,
Expand Down
8 changes: 1 addition & 7 deletions src/buffer/highlights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,7 @@ pub fn view<'a>(
.brackets
.format(user.display(with_access_levels)),
)
.style(|theme| {
theme::selectable_text::nickname(
theme,
user.nick_color(theme.colors(), config.buffer.nickname.color),
user.is_away(),
)
});
.style(|theme| theme::selectable_text::nickname(theme, config, user));

let nick =
user_context::view(text, server, Some(channel), user, current_user, None)
Expand Down
8 changes: 1 addition & 7 deletions src/buffer/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,7 @@ pub fn view<'a>(
.brackets
.format(user.display(with_access_levels)),
)
.style(|theme| {
theme::selectable_text::nickname(
theme,
user.nick_color(theme.colors(), config.buffer.nickname.color),
false,
)
});
.style(|theme| theme::selectable_text::nickname(theme, config, user));

if let Some(width) = max_nick_width {
text = text
Expand Down
12 changes: 6 additions & 6 deletions src/widget/message_content.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use data::appearance::theme::randomize_color;
use data::user::NickColor;
use data::{message, Config};
use iced::widget::span;
use iced::widget::text::Span;
Expand Down Expand Up @@ -69,13 +68,14 @@ fn message_content_impl<'a, T: Copy + 'a, M: 'a>(
.color(theme.colors().buffer.url)
.link(message::Link::Channel(s.as_str().to_string())),
data::message::Fragment::User(user, text) => {
let color_kind = &config.buffer.channel.message.nickname_color;

let NickColor { seed, color } =
user.nick_color(theme.colors(), *color_kind);
let color = theme.colors().buffer.nickname;
let seed = match &config.buffer.channel.message.nickname_color {
data::buffer::Color::Solid => None,
data::buffer::Color::Unique => Some(user.seed()),
};

let color = match seed {
Some(seed) => randomize_color(color, &seed),
Some(seed) => randomize_color(color, seed),
None => theme.colors().text.primary,
};

Expand Down

0 comments on commit fb64e33

Please sign in to comment.