diff --git a/rslib/backend.proto b/rslib/backend.proto index 443a59972..00e2c6671 100644 --- a/rslib/backend.proto +++ b/rslib/backend.proto @@ -234,6 +234,7 @@ service SearchService { rpc JoinSearchNodes(JoinSearchNodesIn) returns (String); rpc ReplaceSearchNode(ReplaceSearchNodeIn) returns (String); rpc FindAndReplace(FindAndReplaceIn) returns (OpChangesWithCount); + rpc BrowserRowForCard(CardID) returns (BrowserRow); } service StatsService { @@ -1038,6 +1039,26 @@ message FindAndReplaceIn { string field_name = 6; } +message BrowserRow { + message Cell { + string text = 1; + bool is_rtl = 2; + } + enum Color { + COLOR_DEFAULT = 0; + COLOR_MARKED = 1; + COLOR_SUSPENDED = 2; + COLOR_FLAG_RED = 3; + COLOR_FLAG_ORANGE = 4; + COLOR_FLAG_GREEN = 5; + COLOR_FLAG_BLUE = 6; + } + repeated Cell cells = 1; + Color color = 2; + string font_name = 3; + uint32 font_size = 4; +} + message AfterNoteUpdatesIn { repeated int64 nids = 1; bool mark_notes_modified = 2; diff --git a/rslib/src/backend/search.rs b/rslib/src/backend/search.rs index ed4c7d497..b6ffde8e1 100644 --- a/rslib/src/backend/search.rs +++ b/rslib/src/backend/search.rs @@ -13,8 +13,9 @@ use crate::{ config::SortKind, prelude::*, search::{ - concatenate_searches, parse_search, replace_search_node, write_nodes, BoolSeparator, Node, - PropertyKind, RatingKind, SearchNode, SortMode, StateKind, TemplateKind, + browser, concatenate_searches, parse_search, replace_search_node, write_nodes, + BoolSeparator, Node, PropertyKind, RatingKind, SearchNode, SortMode, StateKind, + TemplateKind, }, text::escape_anki_wildcards, }; @@ -89,6 +90,10 @@ impl SearchService for Backend { .map(Into::into) }) } + + fn browser_row_for_card(&self, input: pb::CardId) -> Result { + self.with_col(|col| col.browser_row_for_card(input.cid.into()).map(Into::into)) + } } impl TryFrom for Node { @@ -264,3 +269,37 @@ impl From> for SortMode { } } } + +impl From for pb::BrowserRow { + fn from(row: browser::Row) -> Self { + pb::BrowserRow { + cells: row.cells.into_iter().map(Into::into).collect(), + color: row.color.into(), + font_name: row.font.name, + font_size: row.font.size, + } + } +} + +impl From for pb::browser_row::Cell { + fn from(cell: browser::Cell) -> Self { + pb::browser_row::Cell { + text: cell.text, + is_rtl: cell.is_rtl, + } + } +} + +impl From for i32 { + fn from(color: browser::RowColor) -> Self { + match color { + browser::RowColor::Default => pb::browser_row::Color::Default as i32, + browser::RowColor::Marked => pb::browser_row::Color::Marked as i32, + browser::RowColor::Suspended => pb::browser_row::Color::Suspended as i32, + browser::RowColor::FlagRed => pb::browser_row::Color::FlagRed as i32, + browser::RowColor::FlagOrange => pb::browser_row::Color::FlagOrange as i32, + browser::RowColor::FlagGreen => pb::browser_row::Color::FlagGreen as i32, + browser::RowColor::FlagBlue => pb::browser_row::Color::FlagBlue as i32, + } + } +}