Display colon-delimited emoji in nicks
This commit is contained in:
parent
9f7c1fb9c0
commit
16011a267d
6 changed files with 25 additions and 12 deletions
|
|
@ -16,6 +16,7 @@ Procedure when bumping the version number:
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Respect colon-delimited emoji when calculating nick hue
|
- Respect colon-delimited emoji when calculating nick hue
|
||||||
|
- Display colon-delimited emoji in nicks properly
|
||||||
|
|
||||||
## v0.5.2 - 2023-01-14
|
## v0.5.2 - 2023-01-14
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -107,13 +107,13 @@ fn style_me() -> ContentStyle {
|
||||||
|
|
||||||
fn styled_nick(nick: &str) -> Styled {
|
fn styled_nick(nick: &str) -> Styled {
|
||||||
Styled::new_plain("[")
|
Styled::new_plain("[")
|
||||||
.then(nick, util::nick_style(nick))
|
.and_then(util::style_nick(nick, ContentStyle::default()))
|
||||||
.then_plain("]")
|
.then_plain("]")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn styled_nick_me(nick: &str) -> Styled {
|
fn styled_nick_me(nick: &str) -> Styled {
|
||||||
let style = style_me();
|
let style = style_me();
|
||||||
Styled::new("*", style).then(nick, util::nick_style(nick).italic())
|
Styled::new("*", style).and_then(util::style_nick(nick, style))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn styled_content(content: &str) -> Styled {
|
fn styled_content(content: &str) -> Styled {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
use crossterm::style::{Color, ContentStyle, Stylize};
|
use crossterm::style::{Color, ContentStyle, Stylize};
|
||||||
use euphoxide::emoji::Emoji;
|
use euphoxide::emoji::Emoji;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
use toss::styled::Styled;
|
||||||
|
|
||||||
static EMOJI: Lazy<Emoji> = Lazy::new(Emoji::load);
|
pub static EMOJI: Lazy<Emoji> = Lazy::new(Emoji::load);
|
||||||
|
|
||||||
/// Convert HSL to RGB following [this approach from wikipedia][1].
|
/// Convert HSL to RGB following [this approach from wikipedia][1].
|
||||||
///
|
///
|
||||||
|
|
@ -41,7 +42,15 @@ pub fn nick_color(nick: &str) -> (u8, u8, u8) {
|
||||||
hsl_to_rgb(hue, 1.0, 0.72)
|
hsl_to_rgb(hue, 1.0, 0.72)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn nick_style(nick: &str) -> ContentStyle {
|
pub fn nick_style(nick: &str, base: ContentStyle) -> ContentStyle {
|
||||||
let (r, g, b) = nick_color(nick);
|
let (r, g, b) = nick_color(nick);
|
||||||
ContentStyle::default().bold().with(Color::Rgb { r, g, b })
|
base.bold().with(Color::Rgb { r, g, b })
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn style_nick(nick: &str, base: ContentStyle) -> Styled {
|
||||||
|
Styled::new(EMOJI.replace(nick), nick_style(nick, base))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn style_nick_exact(nick: &str, base: ContentStyle) -> Styled {
|
||||||
|
Styled::new(nick, nick_style(nick, base))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
|
use crossterm::style::ContentStyle;
|
||||||
use euphoxide::conn::Joined;
|
use euphoxide::conn::Joined;
|
||||||
use toss::styled::Styled;
|
|
||||||
use toss::terminal::Terminal;
|
use toss::terminal::Terminal;
|
||||||
|
|
||||||
use crate::euph::{self, Room};
|
use crate::euph::{self, Room};
|
||||||
|
|
@ -17,7 +17,7 @@ pub fn new(joined: Joined) -> EditorState {
|
||||||
pub fn widget(editor: &EditorState) -> BoxedWidget {
|
pub fn widget(editor: &EditorState) -> BoxedWidget {
|
||||||
let editor = editor
|
let editor = editor
|
||||||
.widget()
|
.widget()
|
||||||
.highlight(|s| Styled::new(s, euph::nick_style(s)));
|
.highlight(|s| euph::style_nick_exact(s, ContentStyle::default()));
|
||||||
Popup::new(Padding::new(editor).left(1))
|
Popup::new(Padding::new(editor).left(1))
|
||||||
.title("Choose nick")
|
.title("Choose nick")
|
||||||
.inner_padding(false)
|
.inner_padding(false)
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
use std::borrow::Cow;
|
||||||
use std::iter;
|
use std::iter;
|
||||||
|
|
||||||
use crossterm::style::{Color, ContentStyle, Stylize};
|
use crossterm::style::{Color, ContentStyle, Stylize};
|
||||||
|
|
@ -118,7 +119,7 @@ fn render_row(list: &mut List<SessionId>, session: &HalfSession, own_session: &S
|
||||||
let name = "lurk";
|
let name = "lurk";
|
||||||
let style = ContentStyle::default().grey();
|
let style = ContentStyle::default().grey();
|
||||||
let style_inv = ContentStyle::default().black().on_grey();
|
let style_inv = ContentStyle::default().black().on_grey();
|
||||||
(name, style, style_inv, style_inv)
|
(Cow::Borrowed(name), style, style_inv, style_inv)
|
||||||
} else {
|
} else {
|
||||||
let name = &session.name as &str;
|
let name = &session.name as &str;
|
||||||
let (r, g, b) = euph::nick_color(name);
|
let (r, g, b) = euph::nick_color(name);
|
||||||
|
|
@ -126,7 +127,7 @@ fn render_row(list: &mut List<SessionId>, session: &HalfSession, own_session: &S
|
||||||
let style = ContentStyle::default().bold().with(color);
|
let style = ContentStyle::default().bold().with(color);
|
||||||
let style_inv = ContentStyle::default().bold().black().on(color);
|
let style_inv = ContentStyle::default().bold().black().on(color);
|
||||||
let perms_style_inv = ContentStyle::default().black().on(color);
|
let perms_style_inv = ContentStyle::default().black().on(color);
|
||||||
(name, style, style_inv, perms_style_inv)
|
(euph::EMOJI.replace(name), style, style_inv, perms_style_inv)
|
||||||
};
|
};
|
||||||
|
|
||||||
let perms = if session.is_staff {
|
let perms = if session.is_staff {
|
||||||
|
|
@ -145,7 +146,9 @@ fn render_row(list: &mut List<SessionId>, session: &HalfSession, own_session: &S
|
||||||
" "
|
" "
|
||||||
};
|
};
|
||||||
|
|
||||||
let normal = Styled::new_plain(owner).then(name, style).then_plain(perms);
|
let normal = Styled::new_plain(owner)
|
||||||
|
.then(&name, style)
|
||||||
|
.then_plain(perms);
|
||||||
let selected = Styled::new_plain(owner)
|
let selected = Styled::new_plain(owner)
|
||||||
.then(name, style_inv)
|
.then(name, style_inv)
|
||||||
.then(perms, perms_style_inv);
|
.then(perms, perms_style_inv);
|
||||||
|
|
|
||||||
|
|
@ -309,8 +309,8 @@ impl EuphRoom {
|
||||||
if nick.is_empty() {
|
if nick.is_empty() {
|
||||||
info.then_plain(", present without nick")
|
info.then_plain(", present without nick")
|
||||||
} else {
|
} else {
|
||||||
let nick_style = euph::nick_style(nick);
|
info.then_plain(", present as ")
|
||||||
info.then_plain(", present as ").then(nick, nick_style)
|
.and_then(euph::style_nick(nick, ContentStyle::default()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue