mirror of
https://github.com/aljazceru/notedeck.git
synced 2025-12-19 01:24:21 +01:00
args: switch to oot_bitset for arg flags
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
7
Cargo.lock
generated
7
Cargo.lock
generated
@@ -3375,6 +3375,7 @@ dependencies = [
|
|||||||
"nostrdb",
|
"nostrdb",
|
||||||
"notedeck",
|
"notedeck",
|
||||||
"notedeck_ui",
|
"notedeck_ui",
|
||||||
|
"oot_bitset",
|
||||||
"open",
|
"open",
|
||||||
"poll-promise",
|
"poll-promise",
|
||||||
"pretty_assertions",
|
"pretty_assertions",
|
||||||
@@ -3854,6 +3855,12 @@ version = "1.21.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "oot_bitset"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "52ee4aa71e631bae52c51e653fcc29361459759f2c54753dc3968bbc1e9183a3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "opaque-debug"
|
name = "opaque-debug"
|
||||||
version = "0.3.1"
|
version = "0.3.1"
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ secp256k1 = "0.30.0"
|
|||||||
hashbrown = "0.15.2"
|
hashbrown = "0.15.2"
|
||||||
openai-api-rs = "6.0.3"
|
openai-api-rs = "6.0.3"
|
||||||
re_memory = "0.23.4"
|
re_memory = "0.23.4"
|
||||||
|
oot_bitset = "0.1.1"
|
||||||
|
|
||||||
[profile.small]
|
[profile.small]
|
||||||
inherits = 'release'
|
inherits = 'release'
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ base64 = { workspace = true }
|
|||||||
egui-winit = { workspace = true }
|
egui-winit = { workspace = true }
|
||||||
profiling = { workspace = true }
|
profiling = { workspace = true }
|
||||||
hashbrown = { workspace = true }
|
hashbrown = { workspace = true }
|
||||||
|
oot_bitset = { workspace = true }
|
||||||
human_format = "1.1.0"
|
human_format = "1.1.0"
|
||||||
|
|
||||||
[target.'cfg(any(target_os = "windows", target_os = "macos", target_os = "linux"))'.dependencies]
|
[target.'cfg(any(target_os = "windows", target_os = "macos", target_os = "linux"))'.dependencies]
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
args::ColumnsArgs,
|
args::{ColumnsArgs, ColumnsFlag},
|
||||||
column::Columns,
|
column::Columns,
|
||||||
decks::{Decks, DecksCache},
|
decks::{Decks, DecksCache},
|
||||||
draft::Drafts,
|
draft::Drafts,
|
||||||
@@ -395,8 +395,8 @@ impl Damus {
|
|||||||
info!("DecksCache: loading from command line arguments");
|
info!("DecksCache: loading from command line arguments");
|
||||||
let mut columns: Columns = Columns::new();
|
let mut columns: Columns = Columns::new();
|
||||||
let txn = Transaction::new(ctx.ndb).unwrap();
|
let txn = Transaction::new(ctx.ndb).unwrap();
|
||||||
for col in parsed_args.columns {
|
for col in &parsed_args.columns {
|
||||||
let timeline_kind = col.into_timeline_kind();
|
let timeline_kind = col.clone().into_timeline_kind();
|
||||||
if let Some(add_result) = columns.add_new_timeline_column(
|
if let Some(add_result) = columns.add_new_timeline_column(
|
||||||
&mut timeline_cache,
|
&mut timeline_cache,
|
||||||
&txn,
|
&txn,
|
||||||
@@ -437,9 +437,9 @@ impl Damus {
|
|||||||
let debug = ctx.args.debug;
|
let debug = ctx.args.debug;
|
||||||
let support = Support::new(ctx.path);
|
let support = Support::new(ctx.path);
|
||||||
let mut note_options = NoteOptions::default();
|
let mut note_options = NoteOptions::default();
|
||||||
note_options.set_textmode(parsed_args.textmode);
|
note_options.set_textmode(parsed_args.is_flag_set(ColumnsFlag::Textmode));
|
||||||
note_options.set_scramble_text(parsed_args.scramble);
|
note_options.set_scramble_text(parsed_args.is_flag_set(ColumnsFlag::Scramble));
|
||||||
note_options.set_hide_media(parsed_args.no_media);
|
note_options.set_hide_media(parsed_args.is_flag_set(ColumnsFlag::NoMedia));
|
||||||
|
|
||||||
let jobs = JobsCache::default();
|
let jobs = JobsCache::default();
|
||||||
|
|
||||||
@@ -447,7 +447,7 @@ impl Damus {
|
|||||||
|
|
||||||
Self {
|
Self {
|
||||||
subscriptions: Subscriptions::default(),
|
subscriptions: Subscriptions::default(),
|
||||||
since_optimize: parsed_args.since_optimize,
|
since_optimize: parsed_args.is_flag_set(ColumnsFlag::SinceOptimize),
|
||||||
timeline_cache,
|
timeline_cache,
|
||||||
drafts: Drafts::default(),
|
drafts: Drafts::default(),
|
||||||
state: DamusState::Initializing,
|
state: DamusState::Initializing,
|
||||||
|
|||||||
@@ -2,40 +2,58 @@ use std::collections::BTreeSet;
|
|||||||
|
|
||||||
use crate::timeline::TimelineKind;
|
use crate::timeline::TimelineKind;
|
||||||
use enostr::{Filter, Pubkey};
|
use enostr::{Filter, Pubkey};
|
||||||
|
use oot_bitset::{bitset_clear, bitset_get, bitset_set};
|
||||||
use tracing::{debug, error, info};
|
use tracing::{debug, error, info};
|
||||||
|
|
||||||
|
#[repr(u16)]
|
||||||
|
pub enum ColumnsFlag {
|
||||||
|
SinceOptimize,
|
||||||
|
Textmode,
|
||||||
|
Scramble,
|
||||||
|
NoMedia,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct ColumnsArgs {
|
pub struct ColumnsArgs {
|
||||||
pub columns: Vec<ArgColumn>,
|
pub columns: Vec<ArgColumn>,
|
||||||
pub since_optimize: bool,
|
flags: [u16; 2],
|
||||||
pub textmode: bool,
|
|
||||||
pub scramble: bool,
|
|
||||||
pub no_media: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ColumnsArgs {
|
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>) {
|
pub fn parse(args: &[String], deck_author: Option<&Pubkey>) -> (Self, BTreeSet<String>) {
|
||||||
let mut unrecognized_args = BTreeSet::new();
|
let mut unrecognized_args = BTreeSet::new();
|
||||||
let mut res = Self {
|
let mut res = Self {
|
||||||
columns: vec![],
|
columns: vec![],
|
||||||
since_optimize: true,
|
flags: [0; 2],
|
||||||
textmode: false,
|
|
||||||
scramble: false,
|
|
||||||
no_media: false,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// flag defaults
|
||||||
|
res.set_flag(ColumnsFlag::SinceOptimize);
|
||||||
|
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
let len = args.len();
|
let len = args.len();
|
||||||
while i < len {
|
while i < len {
|
||||||
let arg = &args[i];
|
let arg = &args[i];
|
||||||
|
|
||||||
if arg == "--textmode" {
|
if arg == "--textmode" {
|
||||||
res.textmode = true;
|
res.set_flag(ColumnsFlag::Textmode);
|
||||||
} else if arg == "--no-since-optimize" {
|
} else if arg == "--no-since-optimize" {
|
||||||
res.since_optimize = false;
|
res.clear_flag(ColumnsFlag::SinceOptimize);
|
||||||
} else if arg == "--scramble" {
|
} else if arg == "--scramble" {
|
||||||
res.scramble = true;
|
res.set_flag(ColumnsFlag::Scramble);
|
||||||
} else if arg == "--no-media" {
|
} else if arg == "--no-media" {
|
||||||
res.no_media = true;
|
res.set_flag(ColumnsFlag::NoMedia);
|
||||||
} else if arg == "--filter" {
|
} else if arg == "--filter" {
|
||||||
i += 1;
|
i += 1;
|
||||||
let filter = if let Some(next_arg) = args.get(i) {
|
let filter = if let Some(next_arg) = args.get(i) {
|
||||||
@@ -75,7 +93,9 @@ impl ColumnsArgs {
|
|||||||
deck_author.to_owned(),
|
deck_author.to_owned(),
|
||||||
)));
|
)));
|
||||||
} else {
|
} 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" {
|
} else if column_name == "search" {
|
||||||
i += 1;
|
i += 1;
|
||||||
@@ -168,7 +188,7 @@ impl ColumnsArgs {
|
|||||||
|
|
||||||
/// A way to define columns from the commandline. Can be column kinds or
|
/// A way to define columns from the commandline. Can be column kinds or
|
||||||
/// generic queries
|
/// generic queries
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum ArgColumn {
|
pub enum ArgColumn {
|
||||||
Timeline(TimelineKind),
|
Timeline(TimelineKind),
|
||||||
Generic(Vec<Filter>),
|
Generic(Vec<Filter>),
|
||||||
|
|||||||
Reference in New Issue
Block a user