Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor emote parsing, fix some emote display issues #529

Merged
merged 5 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor and optimizations of emote parsing
- Split the to_vec::highlight function into get_emote_span, highlight,
  and build_line
- Fix bug where username highlights was using byte indices, and search
  highlight was using char indices.
- Don't format and clone time_sent string if config.show_datetimes is
  false
- Fix crash when running with both show_datetimes and username_shown set
  to false
- Fix right_align_usernames offset with emojis in username, fix overflow
  when usernames were > NAME_MAX_CHARACTERS len
- Fix emotes smaller than one cell being skipped when trying to display
  them
- Move some emote related functions into utils/
- Add some test for build_line and related functions
  • Loading branch information
Nogesma committed Feb 4, 2024
commit 7ea1157b5d9675187a1e0c8fa67692992a5aa111
5 changes: 3 additions & 2 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ tempfile = "3.9.0"
serde_with = "3.6.0"
once_cell = "1.19.0"
webbrowser = "0.8.12"
memchr = "2.7.1"

[[bin]]
bench = false
Expand Down
7 changes: 1 addition & 6 deletions src/emotes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
downloader::get_emotes,
graphics_protocol::{ApplyCommand, Size},
},
handlers::config::{CompleteConfig, FrontendConfig},
handlers::config::CompleteConfig,
twitch::TwitchAction,
utils::{emotes::get_emote_offset, pathing::cache_path},
};
Expand Down Expand Up @@ -69,11 +69,6 @@
}
}

#[inline]
pub const fn emotes_enabled(frontend: &FrontendConfig) -> bool {
frontend.twitch_emotes || frontend.betterttv_emotes || frontend.seventv_emotes
}

pub async fn send_emotes(config: &CompleteConfig, tx: &Sender<DownloadedEmotes>, channel: &str) {
info!("Starting emotes download.");
match get_emotes(config, channel).await {
Expand Down Expand Up @@ -142,24 +137,24 @@

pub fn overlay_emote(
parent: (u32, u32),
emote: EmoteData,

Check warning on line 140 in src/emotes/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/emotes/mod.rs#L140

Added line #L140 was not covered by tests
layer: u32,
cols: u16,
root_col_offset: u16,
cell_width: u16,

Check warning on line 144 in src/emotes/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/emotes/mod.rs#L142-L144

Added lines #L142 - L144 were not covered by tests
) -> Result<()> {
// Center the overlay on top of the root emote.
let (pixel_offset, col_offset) = get_emote_offset(emote.width as u16, cell_width, cols);

let relative_col_offset = i32::from(root_col_offset) - i32::from(col_offset);

graphics_protocol::Chain::new(
emote.id,
emote.pid,
parent,
layer,
relative_col_offset,
pixel_offset,
)
.apply()

Check warning on line 159 in src/emotes/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/emotes/mod.rs#L146-L159

Added lines #L146 - L159 were not covered by tests
}
7 changes: 5 additions & 2 deletions src/handlers/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ use tokio::{runtime::Handle, task};
use tui::widgets::BorderType;

use crate::{
emotes::{emotes_enabled, graphics_protocol},
emotes::graphics_protocol,
handlers::{
args::{merge_args_into_config, Cli},
interactive::interactive_config,
state::State,
},
utils::pathing::{cache_path, config_path},
utils::{
emotes::emotes_enabled,
pathing::{cache_path, config_path},
},
};

pub type SharedCompleteConfig = Rc<RefCell<CompleteConfig>>;
Expand Down
Loading
Loading