commit e0f2e467d2a7e6c5919571e0c756c66d3882d65c
parent cf1814f25023330fa98e2512b9bae79cd7fc88e4
Author: William Casarin <jb55@jb55.com>
Date: Thu, 10 Jul 2025 13:34:24 -0700
args: switch to oot_bitset for arg flags
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
5 files changed, 50 insertions(+), 21 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
@@ -3375,6 +3375,7 @@ dependencies = [
"nostrdb",
"notedeck",
"notedeck_ui",
+ "oot_bitset",
"open",
"poll-promise",
"pretty_assertions",
@@ -3855,6 +3856,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]]
+name = "oot_bitset"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "52ee4aa71e631bae52c51e653fcc29361459759f2c54753dc3968bbc1e9183a3"
+
+[[package]]
name = "opaque-debug"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
@@ -74,6 +74,7 @@ secp256k1 = "0.30.0"
hashbrown = "0.15.2"
openai-api-rs = "6.0.3"
re_memory = "0.23.4"
+oot_bitset = "0.1.1"
[profile.small]
inherits = 'release'
diff --git a/crates/notedeck_columns/Cargo.toml b/crates/notedeck_columns/Cargo.toml
@@ -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]
diff --git a/crates/notedeck_columns/src/app.rs b/crates/notedeck_columns/src/app.rs
@@ -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,
diff --git a/crates/notedeck_columns/src/args.rs b/crates/notedeck_columns/src/args.rs
@@ -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>),