Skip to content

Commit

Permalink
refactor(term): reduce visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
ymgyt committed May 6, 2024
1 parent ddf2eb1 commit 08df3e5
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 67 deletions.
7 changes: 4 additions & 3 deletions crates/synd_term/src/application/direction.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum Direction {
pub(crate) enum Direction {
Up,
Down,
Left,
Right,
}

#[derive(PartialEq, Eq, Clone, Copy)]
pub enum IndexOutOfRange {
pub(crate) enum IndexOutOfRange {
Wrapping,
#[allow(dead_code)]
Saturating,
}

Expand All @@ -18,7 +19,7 @@ impl Direction {
clippy::cast_possible_truncation,
clippy::cast_possible_wrap
)]
pub fn apply(&self, index: usize, len: usize, out: IndexOutOfRange) -> usize {
pub(crate) fn apply(self, index: usize, len: usize, out: IndexOutOfRange) -> usize {
if len == 0 {
return index;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/synd_term/src/application/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::command::Command;
mod key_handlers;
pub use key_handlers::{KeyHandler, KeyHandlers};

pub enum KeyEventResult {
pub(crate) enum KeyEventResult {
Consumed(Option<Command>),
Ignored,
}
3 changes: 0 additions & 3 deletions crates/synd_term/src/application/input_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ use crate::{
types::{self},
};

pub use feed::requirement as parse_requirement;

// type NomError<'s> = nom::error::Error<&'s str>;
type NomError<'s> = nom::error::VerboseError<&'s str>;

const CTX_REQUIREMENT: &str = "requirement";
Expand Down
30 changes: 11 additions & 19 deletions crates/synd_term/src/application/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,19 @@ use crate::{
};

mod direction;
pub use direction::{Direction, IndexOutOfRange};
pub(crate) use direction::{Direction, IndexOutOfRange};

mod in_flight;
pub use in_flight::{InFlight, RequestId, RequestSequence};
pub(crate) use in_flight::{InFlight, RequestId, RequestSequence};

mod input_parser;
pub use input_parser::parse_requirement;
use input_parser::InputParser;

mod authenticator;
pub use authenticator::{Authenticator, DeviceFlows, JwtService};

mod clock;
pub use clock::{Clock, SystemClock};
pub(crate) use clock::{Clock, SystemClock};

mod flags;
use flags::Should;
Expand Down Expand Up @@ -165,10 +164,6 @@ impl Application {
&self.authenticator.jwt_service
}

pub fn jobs_mut(&mut self) -> &mut Jobs {
&mut self.jobs
}

fn keymaps(&mut self) -> &mut Keymaps {
self.key_handlers.keymaps_mut().unwrap()
}
Expand Down Expand Up @@ -312,7 +307,7 @@ impl Application {
}
}
Command::MoveAuthenticationProvider(direction) => {
self.components.auth.move_selection(&direction);
self.components.auth.move_selection(direction);
self.should_render();
}
Command::DeviceAuthorizationFlow {
Expand Down Expand Up @@ -347,7 +342,7 @@ impl Application {
self.keymaps().toggle(KeymapId::Entries);
self.keymaps().toggle(KeymapId::Subscription);

match self.components.tabs.move_selection(&direction) {
match self.components.tabs.move_selection(direction) {
Tab::Feeds if !self.components.subscription.has_subscription() => {
next = Some(Command::FetchSubscription {
after: None,
Expand All @@ -359,7 +354,7 @@ impl Application {
self.should_render();
}
Command::MoveSubscribedFeed(direction) => {
self.components.subscription.move_selection(&direction);
self.components.subscription.move_selection(direction);
self.should_render();
}
Command::MoveSubscribedFeedFirst => {
Expand Down Expand Up @@ -409,10 +404,6 @@ impl Application {
self.subscribe_feed(input);
self.should_render();
}
Command::UnsubscribeFeed { url } => {
self.unsubscribe_feed(url);
self.should_render();
}
Command::FetchSubscription { after, first } => {
self.fetch_subscription(Populate::Append, after, first);
}
Expand Down Expand Up @@ -512,7 +503,7 @@ impl Application {
self.should_render();
}
Command::MoveEntry(direction) => {
self.components.entries.move_selection(&direction);
self.components.entries.move_selection(direction);
self.should_render();
}
Command::MoveEntryFirst => {
Expand Down Expand Up @@ -605,9 +596,10 @@ impl Application {

fn handle_terminal_event(&mut self, event: std::io::Result<CrosstermEvent>) -> Option<Command> {
match event.unwrap() {
CrosstermEvent::Resize(columns, rows) => {
Some(Command::ResizeTerminal { columns, rows })
}
CrosstermEvent::Resize(columns, rows) => Some(Command::ResizeTerminal {
_columns: columns,
_rows: rows,
}),
CrosstermEvent::Key(KeyEvent {
kind: KeyEventKind::Release,
..
Expand Down
9 changes: 3 additions & 6 deletions crates/synd_term/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ use crate::{
};

#[derive(Debug, Clone)]
pub enum Command {
pub(crate) enum Command {
Quit,
ResizeTerminal {
columns: u16,
rows: u16,
_columns: u16,
_rows: u16,
},
RenderThrobber,
Idle,
Expand Down Expand Up @@ -52,9 +52,6 @@ pub enum Command {
SubscribeFeed {
input: SubscribeFeedInput,
},
UnsubscribeFeed {
url: FeedUrl,
},
CompleteSubscribeFeed {
feed: Feed,
request_seq: RequestSequence,
Expand Down
4 changes: 2 additions & 2 deletions crates/synd_term/src/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use futures_util::{future::BoxFuture, stream::FuturesUnordered};

use crate::command::Command;

pub type JobFuture = BoxFuture<'static, anyhow::Result<Command>>;
pub(crate) type JobFuture = BoxFuture<'static, anyhow::Result<Command>>;

pub struct Jobs {
pub(crate) struct Jobs {
pub futures: FuturesUnordered<JobFuture>,
}

Expand Down
15 changes: 6 additions & 9 deletions crates/synd_term/src/keymap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub mod macros;
use crate::{application::event::KeyEventResult, command::Command};

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum KeymapId {
pub(crate) enum KeymapId {
Global = 0,
Login = 1,
Tabs = 2,
Expand All @@ -22,7 +22,8 @@ pub enum KeymapId {
}

#[derive(Debug)]
pub struct Keymap {
pub(crate) struct Keymap {
#[allow(dead_code)]
id: KeymapId,
enable: bool,
trie: KeyTrie,
Expand All @@ -44,10 +45,6 @@ impl Keymap {
Self::new(id, KeyTrie::Node(KeyTrieNode { map }))
}

pub fn id(&self) -> KeymapId {
self.id
}

fn search(&mut self, event: &KeyEvent) -> Option<Command> {
let first = self.pending_keys.first().unwrap_or(event);
let trie = match self.trie.search(&[*first]) {
Expand All @@ -71,7 +68,7 @@ impl Keymap {
}
}

pub struct KeymapsConfig {
pub(crate) struct KeymapsConfig {
pub login: KeyTrie,
pub tabs: KeyTrie,
pub entries: KeyTrie,
Expand All @@ -88,7 +85,7 @@ impl Default for KeymapsConfig {
}

#[derive(Debug)]
pub struct Keymaps {
pub(crate) struct Keymaps {
keymaps: Vec<Keymap>,
}

Expand Down Expand Up @@ -148,7 +145,7 @@ impl Default for Keymaps {
}

#[derive(Clone, Debug)]
pub enum KeyTrie {
pub(crate) enum KeyTrie {
Command(Command),
Node(KeyTrieNode),
}
Expand Down
4 changes: 2 additions & 2 deletions crates/synd_term/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
#![warn(rustdoc::broken_intra_doc_links)]

pub mod application;
pub mod auth;
pub(crate) mod auth;
pub mod cli;
pub mod client;
pub mod command;
pub(crate) mod command;
pub mod config;
pub mod interact;
pub mod job;
Expand Down
6 changes: 3 additions & 3 deletions crates/synd_term/src/ui/components/authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ use crate::{

/// Handle user authentication
#[derive(PartialEq, Eq)]
pub enum AuthenticateState {
pub(crate) enum AuthenticateState {
NotAuthenticated,
DeviceFlow(DeviceAuthorizationResponse),
Authenticated,
}

pub struct Authentication {
pub(crate) struct Authentication {
state: AuthenticateState,
providers: Vec<AuthenticationProvider>,
selected_provider_index: usize,
Expand All @@ -49,7 +49,7 @@ impl Authentication {
self.providers[self.selected_provider_index]
}

pub fn move_selection(&mut self, direction: &Direction) {
pub fn move_selection(&mut self, direction: Direction) {
self.selected_provider_index = direction.apply(
self.selected_provider_index,
self.providers.len(),
Expand Down
5 changes: 3 additions & 2 deletions crates/synd_term/src/ui/components/entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ use ratatui::{
};
use synd_feed::types::FeedUrl;

pub struct Entries {
#[allow(clippy::struct_field_names)]
pub(crate) struct Entries {
selected_entry_index: usize,
entries: Vec<types::Entry>,
effective_entries: Vec<usize>,
Expand Down Expand Up @@ -76,7 +77,7 @@ impl Entries {
self.apply_filter();
}

pub fn move_selection(&mut self, direction: &Direction) {
pub fn move_selection(&mut self, direction: Direction) {
self.selected_entry_index = direction.apply(
self.selected_entry_index,
self.effective_entries.len(),
Expand Down
8 changes: 4 additions & 4 deletions crates/synd_term/src/ui/components/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ static LABELS: &[char] = &[
];

#[derive(Clone, Copy, PartialEq, Eq)]
pub enum FilterResult {
pub(crate) enum FilterResult {
Use,
Discard,
}

#[derive(Clone)]
pub struct FeedFilter {
pub(crate) struct FeedFilter {
requirement: Requirement,
categories: HashMap<Category<'static>, FilterCategoryState>,
matcher: Matcher,
Expand Down Expand Up @@ -96,7 +96,7 @@ impl FeedFilter {
}

#[derive(Debug)]
pub struct Filter {
pub(crate) struct Filter {
state: State,
requirement: Requirement,
categories: Vec<Category<'static>>,
Expand All @@ -114,7 +114,7 @@ enum State {
}

#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum FilterCategoryState {
pub(crate) enum FilterCategoryState {
Active,
Inactive,
}
Expand Down
16 changes: 8 additions & 8 deletions crates/synd_term/src/ui/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ use crate::{
},
};

pub mod authentication;
pub mod entries;
pub mod filter;
pub mod root;
pub mod status;
pub mod subscription;
pub mod tabs;
pub(crate) mod authentication;
pub(crate) mod entries;
pub(crate) mod filter;
pub(crate) mod root;
pub(crate) mod status;
pub(crate) mod subscription;
pub(crate) mod tabs;

pub struct Components {
pub(crate) struct Components {
pub tabs: Tabs,
pub filter: Filter,
pub prompt: StatusLine,
Expand Down
4 changes: 2 additions & 2 deletions crates/synd_term/src/ui/components/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ impl Subscription {
pub fn remove_unsubscribed_feed(&mut self, url: &FeedUrl) {
self.feeds.retain(|feed_meta| &feed_meta.url != url);
self.apply_filter();
self.move_selection(&Direction::Up);
self.move_selection(Direction::Up);
}

pub fn move_selection(&mut self, direction: &Direction) {
pub fn move_selection(&mut self, direction: Direction) {
self.selected_feed_index = direction.apply(
self.selected_feed_index,
self.effective_feeds.len(),
Expand Down
2 changes: 1 addition & 1 deletion crates/synd_term/src/ui/components/tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Tabs {
}
}

pub fn move_selection(&mut self, direction: &Direction) -> Tab {
pub fn move_selection(&mut self, direction: Direction) -> Tab {
self.selected = direction.apply(self.selected, self.tabs.len(), IndexOutOfRange::Wrapping);
self.current()
}
Expand Down
4 changes: 2 additions & 2 deletions crates/synd_term/src/ui/widgets/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ enum Move {
}

#[derive(Debug)]
pub struct Prompt {
pub(crate) struct Prompt {
line: String,
cursor: usize,
}
Expand All @@ -43,7 +43,7 @@ impl Prompt {
}

#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum RenderCursor {
pub(crate) enum RenderCursor {
Enable,
Disable,
}
Expand Down

0 comments on commit 08df3e5

Please sign in to comment.