diff --git a/Cargo.lock b/Cargo.lock index 9ad86cd..25d7386 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -247,6 +247,7 @@ dependencies = [ "serde", "serde_json", "serde_qs", + "serde_repr", "serde_with", "tokio", "words-count", @@ -1133,6 +1134,17 @@ dependencies = [ "thiserror", ] +[[package]] +name = "serde_repr" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8725e1dfadb3a50f7e5ce0b1a540466f6ed3fe7a0fca2ac2b8b831d31316bd00" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "serde_urlencoded" version = "0.7.1" diff --git a/Cargo.toml b/Cargo.toml index d6faf0b..9d22755 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,6 +32,7 @@ serde = { version = "1.0.188", features = ["derive"] } serde_qs = "0.12.0" serde_json = "1.0.106" serde_with = "3.3.0" +serde_repr = "0.1.16" home = "0.5.5" chrono = "0.4.30" diff --git a/src/api/ing/get_list.rs b/src/api/ing/get_list.rs index 6438960..46c0e1a 100644 --- a/src/api/ing/get_list.rs +++ b/src/api/ing/get_list.rs @@ -1,4 +1,4 @@ -use crate::api::ing::{Ing, IngType}; +use crate::api::ing::{Ing, IngSendFrom, IngType}; use crate::infra::http::{body_or_err, RequestBuilderExt}; use crate::infra::json; use crate::infra::result::IntoResult; @@ -31,7 +31,7 @@ pub struct IngEntry { #[serde(rename = "UserGuid")] pub user_guid: String, #[serde(rename = "SendFrom")] - pub send_from: usize, + pub send_from: IngSendFrom, #[serde(rename = "Icons")] pub icons: String, } diff --git a/src/api/ing/mod.rs b/src/api/ing/mod.rs index 95dbfdd..4da6682 100644 --- a/src/api/ing/mod.rs +++ b/src/api/ing/mod.rs @@ -5,6 +5,7 @@ use crate::infra::result::IntoResult; use anyhow::bail; use lazy_static::lazy_static; use regex::Regex; +use serde_repr::{Deserialize_repr, Serialize_repr}; pub mod get_comment_list; pub mod get_list; @@ -31,7 +32,8 @@ pub enum IngType { Mention = 14, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize_repr, Deserialize_repr)] +#[repr(u8)] pub enum IngSendFrom { None = 0, Ms = 1, diff --git a/src/display/colorful.rs b/src/display/colorful.rs index d57b801..0042cc3 100644 --- a/src/display/colorful.rs +++ b/src/display/colorful.rs @@ -1,6 +1,6 @@ use crate::api::ing::get_list::{IngCommentEntry, IngEntry}; use crate::api::ing::{ - fmt_content, get_ing_at_user_tag_text, ing_star_tag_to_text, rm_ing_at_user_tag, + fmt_content, get_ing_at_user_tag_text, ing_star_tag_to_text, rm_ing_at_user_tag, IngSendFrom, }; use crate::api::news::get_list::NewsEntry; use crate::api::post::get_one::PostEntry; @@ -67,6 +67,16 @@ pub fn list_ing(ing_list: &Result)>>, rev: b }; print!("{}", create_time.dimmed()); + let send_from_mark = match ing.send_from { + IngSendFrom::Cli => Some("CLI"), + IngSendFrom::CellPhone => Some("Mobile"), + IngSendFrom::VsCode => Some("VSCode"), + IngSendFrom::Web => Some("Web"), + _ => None, + }; + if let Some(mark) = send_from_mark { + print!(" {}", mark.dimmed()); + } if ing.is_lucky { let star_text = ing_star_tag_to_text(&ing.icons); print!(" {}⭐", star_text.yellow()); diff --git a/src/display/normal.rs b/src/display/normal.rs index c8ca863..ca98ff8 100644 --- a/src/display/normal.rs +++ b/src/display/normal.rs @@ -1,6 +1,6 @@ use crate::api::ing::get_list::{IngCommentEntry, IngEntry}; use crate::api::ing::{ - fmt_content, get_ing_at_user_tag_text, ing_star_tag_to_text, rm_ing_at_user_tag, + fmt_content, get_ing_at_user_tag_text, ing_star_tag_to_text, rm_ing_at_user_tag, IngSendFrom, }; use crate::api::news::get_list::NewsEntry; use crate::api::post::get_one::PostEntry; @@ -9,6 +9,7 @@ use crate::infra::iter::IteratorExt; use crate::infra::time::patch_rfc3339; use anyhow::Result; use chrono::DateTime; +use colored::Colorize; use std::fmt::Display; use std::ops::Not; use std::path::PathBuf; @@ -66,6 +67,16 @@ pub fn list_ing(ing_list: &Result)>>, rev: b }; print!("{}", create_time); + let send_from_mark = match ing.send_from { + IngSendFrom::Cli => Some("CLI"), + IngSendFrom::CellPhone => Some("Mobile"), + IngSendFrom::VsCode => Some("VSCode"), + IngSendFrom::Web => Some("Web"), + _ => None, + }; + if let Some(mark) = send_from_mark { + print!(" {}", mark.dimmed()); + } if ing.is_lucky { let star_text = ing_star_tag_to_text(&ing.icons); print!(" {}⭐", star_text);