Add pronoun presets
This commit is contained in:
parent
7744cfe66a
commit
e1e747d107
62
src/main.rs
62
src/main.rs
|
@ -5,6 +5,7 @@ use protocol_derive::{Decode, Encode};
|
|||
use std::collections::HashMap;
|
||||
use std::net::{SocketAddr, ToSocketAddrs, UdpSocket};
|
||||
|
||||
mod pronouns;
|
||||
mod tui;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
|
@ -47,67 +48,6 @@ pub struct UserInfo {
|
|||
pub about: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Decode, Encode)]
|
||||
pub struct Pronouns {
|
||||
pub case_sensitive: bool,
|
||||
pub plural: bool,
|
||||
|
||||
/// Ex. he, she, they, fae.
|
||||
pub subject: String,
|
||||
|
||||
/// Ex. him, her, them, faer.
|
||||
pub object: String,
|
||||
|
||||
/// Ex. his, her, their, faer.
|
||||
pub possessive: String,
|
||||
|
||||
/// Ex. his, hers, theirs, faers.
|
||||
pub possessive_pronoun: String,
|
||||
|
||||
/// Ex. himself, herself, themself, faerself.
|
||||
pub reflexive: String,
|
||||
}
|
||||
|
||||
impl Pronouns {
|
||||
pub fn format_short(&self) -> String {
|
||||
format!("{}/{}", self.subject, self.object)
|
||||
}
|
||||
|
||||
pub fn format_pronouns(&self) -> String {
|
||||
format!(
|
||||
"{}/{}/{}/{}/{}",
|
||||
self.subject, self.object, self.possessive, self.possessive_pronoun, self.reflexive
|
||||
)
|
||||
}
|
||||
|
||||
pub fn format_usage(&self) -> Option<String> {
|
||||
let mut usages = Vec::new();
|
||||
|
||||
if self.plural {
|
||||
usages.push("plural");
|
||||
}
|
||||
|
||||
if self.case_sensitive {
|
||||
usages.push("case-sensitive");
|
||||
}
|
||||
|
||||
if usages.len() > 0 {
|
||||
Some(usages.join(", "))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn format_full(&self) -> String {
|
||||
let pronouns = self.format_pronouns();
|
||||
if let Some(usage) = self.format_usage() {
|
||||
format!("{} [{}]", pronouns, usage)
|
||||
} else {
|
||||
pronouns
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Decode, Encode)]
|
||||
pub struct RoomInfo {
|
||||
pub id: String,
|
||||
|
|
|
@ -0,0 +1,101 @@
|
|||
use protocol_derive::{Decode, Encode};
|
||||
|
||||
pub fn make_presets() -> Vec<Pronouns> {
|
||||
// TODO add more from https://pronoun.is and https://askanonbinary.tumblr.com/pronouns
|
||||
let presets = [
|
||||
(false, false, "she", "her", "her", "hers", "herself"),
|
||||
(false, false, "he", "him", "him", "him", "himself"),
|
||||
(false, false, "they", "them", "their", "theirs", "themself"),
|
||||
(false, true, "they", "them", "their", "theirs", "themselves"),
|
||||
(false, false, "fae", "faer", "faer", "faers", "faerself"),
|
||||
(false, false, "e", "em", "eir", "eirs", "emself"),
|
||||
(true, false, "E", "Em", "Eir", "Eirs", "Emself"),
|
||||
(false, false, "it", "its", "its", "its", "itself"),
|
||||
];
|
||||
|
||||
presets
|
||||
.iter()
|
||||
.map(
|
||||
|(
|
||||
case_sensitive,
|
||||
plural,
|
||||
subject,
|
||||
object,
|
||||
possessive,
|
||||
possessive_pronoun,
|
||||
reflexive,
|
||||
)| {
|
||||
Pronouns {
|
||||
case_sensitive: *case_sensitive,
|
||||
plural: *plural,
|
||||
subject: subject.to_string(),
|
||||
object: object.to_string(),
|
||||
possessive: possessive.to_string(),
|
||||
possessive_pronoun: possessive_pronoun.to_string(),
|
||||
reflexive: reflexive.to_string(),
|
||||
}
|
||||
},
|
||||
)
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Decode, Encode)]
|
||||
pub struct Pronouns {
|
||||
pub case_sensitive: bool,
|
||||
pub plural: bool,
|
||||
|
||||
/// Ex. he, she, they, fae.
|
||||
pub subject: String,
|
||||
|
||||
/// Ex. him, her, them, faer.
|
||||
pub object: String,
|
||||
|
||||
/// Ex. his, her, their, faer.
|
||||
pub possessive: String,
|
||||
|
||||
/// Ex. his, hers, theirs, faers.
|
||||
pub possessive_pronoun: String,
|
||||
|
||||
/// Ex. himself, herself, themself, faerself.
|
||||
pub reflexive: String,
|
||||
}
|
||||
|
||||
impl Pronouns {
|
||||
pub fn format_short(&self) -> String {
|
||||
format!("{}/{}", self.subject, self.object)
|
||||
}
|
||||
|
||||
pub fn format_pronouns(&self) -> String {
|
||||
format!(
|
||||
"{}/{}/{}/{}/{}",
|
||||
self.subject, self.object, self.possessive, self.possessive_pronoun, self.reflexive
|
||||
)
|
||||
}
|
||||
|
||||
pub fn format_usage(&self) -> Option<String> {
|
||||
let mut usages = Vec::new();
|
||||
|
||||
if self.plural {
|
||||
usages.push("plural");
|
||||
}
|
||||
|
||||
if self.case_sensitive {
|
||||
usages.push("case-sensitive");
|
||||
}
|
||||
|
||||
if usages.len() > 0 {
|
||||
Some(usages.join(", "))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn format_full(&self) -> String {
|
||||
let pronouns = self.format_pronouns();
|
||||
if let Some(usage) = self.format_usage() {
|
||||
format!("{} [{}]", pronouns, usage)
|
||||
} else {
|
||||
pronouns
|
||||
}
|
||||
}
|
||||
}
|
57
src/tui.rs
57
src/tui.rs
|
@ -1,4 +1,4 @@
|
|||
use crate::Pronouns;
|
||||
use crate::pronouns::Pronouns;
|
||||
use crossbeam_channel::{Receiver, Sender};
|
||||
use cursive::align::*;
|
||||
use cursive::theme::*;
|
||||
|
@ -104,25 +104,44 @@ impl Tui {
|
|||
}
|
||||
|
||||
pub fn select_pronouns(siv: &mut Cursive) {
|
||||
let mut dialog = Dialog::new();
|
||||
dialog.set_title("Select Pronouns");
|
||||
dialog.add_button("Custom...", |siv| {
|
||||
siv.pop_layer();
|
||||
Self::edit_pronouns(siv);
|
||||
});
|
||||
dialog.add_button("None", |siv| {
|
||||
siv.with_user_data(|sender: &mut Sender<EditEvent>| {
|
||||
sender.send(EditEvent::Pronouns(None)).unwrap();
|
||||
});
|
||||
siv.call_on_name("pronouns_text", |view: &mut TextView| {
|
||||
view.set_content("<none>");
|
||||
let presets = SelectView::new()
|
||||
.with_all(
|
||||
crate::pronouns::make_presets()
|
||||
.into_iter()
|
||||
.map(|pronouns| (pronouns.format_full(), pronouns)),
|
||||
)
|
||||
.on_submit(|siv, pronouns| {
|
||||
siv.with_user_data(|sender: &mut Sender<EditEvent>| {
|
||||
sender
|
||||
.send(EditEvent::Pronouns(Some(pronouns.clone())))
|
||||
.unwrap();
|
||||
});
|
||||
|
||||
siv.call_on_name("pronouns_text", |view: &mut TextView| {
|
||||
view.set_content(pronouns.format_full());
|
||||
})
|
||||
.unwrap();
|
||||
siv.pop_layer();
|
||||
})
|
||||
.unwrap();
|
||||
siv.pop_layer();
|
||||
});
|
||||
dialog.add_button("Cancel", |siv| {
|
||||
siv.pop_layer().unwrap();
|
||||
});
|
||||
.scrollable();
|
||||
|
||||
let dialog = Dialog::around(presets)
|
||||
.title("Select Pronouns")
|
||||
.button("Custom...", |siv| {
|
||||
siv.pop_layer();
|
||||
Self::edit_pronouns(siv);
|
||||
})
|
||||
.button("None", |siv| {
|
||||
siv.with_user_data(|sender: &mut Sender<EditEvent>| {
|
||||
sender.send(EditEvent::Pronouns(None)).unwrap();
|
||||
});
|
||||
siv.call_on_name("pronouns_text", |view: &mut TextView| {
|
||||
view.set_content("<none>");
|
||||
})
|
||||
.unwrap();
|
||||
siv.pop_layer();
|
||||
})
|
||||
.dismiss_button("Cancel");
|
||||
siv.add_layer(dialog);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue