mirror of
https://github.com/aljazceru/notedeck.git
synced 2025-12-18 17:14:21 +01:00
args: switch to oot_bitset for arg flags
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -52,6 +52,7 @@ base64 = { workspace = true }
|
||||
egui-winit = { workspace = true }
|
||||
profiling = { workspace = true }
|
||||
hashbrown = { workspace = true }
|
||||
oot_bitset = { workspace = true }
|
||||
human_format = "1.1.0"
|
||||
|
||||
[target.'cfg(any(target_os = "windows", target_os = "macos", target_os = "linux"))'.dependencies]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
args::ColumnsArgs,
|
||||
args::{ColumnsArgs, ColumnsFlag},
|
||||
column::Columns,
|
||||
decks::{Decks, DecksCache},
|
||||
draft::Drafts,
|
||||
@@ -395,8 +395,8 @@ impl Damus {
|
||||
info!("DecksCache: loading from command line arguments");
|
||||
let mut columns: Columns = Columns::new();
|
||||
let txn = Transaction::new(ctx.ndb).unwrap();
|
||||
for col in parsed_args.columns {
|
||||
let timeline_kind = col.into_timeline_kind();
|
||||
for col in &parsed_args.columns {
|
||||
let timeline_kind = col.clone().into_timeline_kind();
|
||||
if let Some(add_result) = columns.add_new_timeline_column(
|
||||
&mut timeline_cache,
|
||||
&txn,
|
||||
@@ -437,9 +437,9 @@ impl Damus {
|
||||
let debug = ctx.args.debug;
|
||||
let support = Support::new(ctx.path);
|
||||
let mut note_options = NoteOptions::default();
|
||||
note_options.set_textmode(parsed_args.textmode);
|
||||
note_options.set_scramble_text(parsed_args.scramble);
|
||||
note_options.set_hide_media(parsed_args.no_media);
|
||||
note_options.set_textmode(parsed_args.is_flag_set(ColumnsFlag::Textmode));
|
||||
note_options.set_scramble_text(parsed_args.is_flag_set(ColumnsFlag::Scramble));
|
||||
note_options.set_hide_media(parsed_args.is_flag_set(ColumnsFlag::NoMedia));
|
||||
|
||||
let jobs = JobsCache::default();
|
||||
|
||||
@@ -447,7 +447,7 @@ impl Damus {
|
||||
|
||||
Self {
|
||||
subscriptions: Subscriptions::default(),
|
||||
since_optimize: parsed_args.since_optimize,
|
||||
since_optimize: parsed_args.is_flag_set(ColumnsFlag::SinceOptimize),
|
||||
timeline_cache,
|
||||
drafts: Drafts::default(),
|
||||
state: DamusState::Initializing,
|
||||
|
||||
@@ -2,40 +2,58 @@ use std::collections::BTreeSet;
|
||||
|
||||
use crate::timeline::TimelineKind;
|
||||
use enostr::{Filter, Pubkey};
|
||||
use oot_bitset::{bitset_clear, bitset_get, bitset_set};
|
||||
use tracing::{debug, error, info};
|
||||
|
||||
#[repr(u16)]
|
||||
pub enum ColumnsFlag {
|
||||
SinceOptimize,
|
||||
Textmode,
|
||||
Scramble,
|
||||
NoMedia,
|
||||
}
|
||||
|
||||
pub struct ColumnsArgs {
|
||||
pub columns: Vec<ArgColumn>,
|
||||
pub since_optimize: bool,
|
||||
pub textmode: bool,
|
||||
pub scramble: bool,
|
||||
pub no_media: bool,
|
||||
flags: [u16; 2],
|
||||
}
|
||||
|
||||
impl ColumnsArgs {
|
||||
pub fn is_flag_set(&self, flag: ColumnsFlag) -> bool {
|
||||
bitset_get(&self.flags, flag as u16)
|
||||
}
|
||||
|
||||
pub fn set_flag(&mut self, flag: ColumnsFlag) {
|
||||
bitset_set(&mut self.flags, flag as u16)
|
||||
}
|
||||
|
||||
pub fn clear_flag(&mut self, flag: ColumnsFlag) {
|
||||
bitset_clear(&mut self.flags, flag as u16)
|
||||
}
|
||||
|
||||
pub fn parse(args: &[String], deck_author: Option<&Pubkey>) -> (Self, BTreeSet<String>) {
|
||||
let mut unrecognized_args = BTreeSet::new();
|
||||
let mut res = Self {
|
||||
columns: vec![],
|
||||
since_optimize: true,
|
||||
textmode: false,
|
||||
scramble: false,
|
||||
no_media: false,
|
||||
flags: [0; 2],
|
||||
};
|
||||
|
||||
// flag defaults
|
||||
res.set_flag(ColumnsFlag::SinceOptimize);
|
||||
|
||||
let mut i = 0;
|
||||
let len = args.len();
|
||||
while i < len {
|
||||
let arg = &args[i];
|
||||
|
||||
if arg == "--textmode" {
|
||||
res.textmode = true;
|
||||
res.set_flag(ColumnsFlag::Textmode);
|
||||
} else if arg == "--no-since-optimize" {
|
||||
res.since_optimize = false;
|
||||
res.clear_flag(ColumnsFlag::SinceOptimize);
|
||||
} else if arg == "--scramble" {
|
||||
res.scramble = true;
|
||||
res.set_flag(ColumnsFlag::Scramble);
|
||||
} else if arg == "--no-media" {
|
||||
res.no_media = true;
|
||||
res.set_flag(ColumnsFlag::NoMedia);
|
||||
} else if arg == "--filter" {
|
||||
i += 1;
|
||||
let filter = if let Some(next_arg) = args.get(i) {
|
||||
@@ -75,7 +93,9 @@ impl ColumnsArgs {
|
||||
deck_author.to_owned(),
|
||||
)));
|
||||
} else {
|
||||
panic!("No accounts available, could not handle implicit pubkey contacts column");
|
||||
panic!(
|
||||
"No accounts available, could not handle implicit pubkey contacts column"
|
||||
);
|
||||
}
|
||||
} else if column_name == "search" {
|
||||
i += 1;
|
||||
@@ -168,7 +188,7 @@ impl ColumnsArgs {
|
||||
|
||||
/// A way to define columns from the commandline. Can be column kinds or
|
||||
/// generic queries
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ArgColumn {
|
||||
Timeline(TimelineKind),
|
||||
Generic(Vec<Filter>),
|
||||
|
||||
Reference in New Issue
Block a user