Commit 8d8af112d7
Unregistered key
Layout: unified · split
.github/workflows/check-imports-format.sh added +89
| @@ -0,0 +1,89 @@ | ||
| 1 | #!/bin/sh | |
| 2 | ||
| 3 | while [ $# -gt 0 ]; do | |
| 4 | # check that all imports for a `use` statement come from the same module | |
| 5 | import_error=$(sed -n " | |
| 6 | # only consider use statements with braces | |
| 7 | /^ *use .*{/ { | |
| 8 | # load the import until the first closing brace into the pattern space | |
| 9 | :find-close | |
| 10 | /^[^}]*$/ { | |
| 11 | N | |
| 12 | b find-close | |
| 13 | } | |
| 14 | ||
| 15 | # show error if multiple braces exist | |
| 16 | /{.*{/ { | |
| 17 | i\\ | |
| 18 | invalid import in '$1' line: | |
| 19 | = | |
| 20 | i\\ | |
| 21 | containing multiple braces in one import: | |
| 22 | p | |
| 23 | b | |
| 24 | } | |
| 25 | ||
| 26 | # show error if qualified paths exist inside braces | |
| 27 | /{.*::/ { | |
| 28 | i\\ | |
| 29 | invalid import in '$1' line: | |
| 30 | = | |
| 31 | i\\ | |
| 32 | containing a qualified import inside braces: | |
| 33 | p | |
| 34 | b | |
| 35 | } | |
| 36 | } | |
| 37 | " "$1") | |
| 38 | if [ -n "$import_error" ]; then | |
| 39 | printf "%s\n" "$import_error" | |
| 40 | exit 1 | |
| 41 | fi | |
| 42 | ||
| 43 | # check that imports are sorted as `std`, `other imports`, `crate` each seperated by a blank line | |
| 44 | import_pattern=$(sed -n " | |
| 45 | # include blank lines | |
| 46 | /^$/ { | |
| 47 | p | |
| 48 | d | |
| 49 | } | |
| 50 | # include std imports | |
| 51 | /^use std::/ { | |
| 52 | i\\ | |
| 53 | use std | |
| 54 | d | |
| 55 | } | |
| 56 | # include crate imports | |
| 57 | /^use crate::/ { | |
| 58 | i\\ | |
| 59 | use crate | |
| 60 | d | |
| 61 | } | |
| 62 | # include other imports without the target | |
| 63 | s/^use .*/use/p | |
| 64 | " "$1" | uniq | tr "\n" "_") # remove duplicates; we only care for the order of the imports; also grep doesn't play nice with line breaks | |
| 65 | ||
| 66 | # check that the pattern if followed | |
| 67 | printf "%s" "$import_pattern" | grep -q "^_\?\(use std__\)\?\(use__\)\?\(use crate__\)\?_\?$" | |
| 68 | if [ $? -ne 0 ]; then | |
| 69 | printf "imports in '%s' dont follow the pattern: | |
| 70 | \`\`\` | |
| 71 | use std::*; | |
| 72 | ||
| 73 | use *; | |
| 74 | ||
| 75 | use crate::*; | |
| 76 | ||
| 77 | \`\`\` | |
| 78 | ||
| 79 | instead is has the pattern: | |
| 80 | \`\`\` | |
| 81 | %s | |
| 82 | \`\`\` | |
| 83 | " "$1" "$import_pattern" | tr "_" "\n" >&2 | |
| 84 | exit 1 | |
| 85 | fi | |
| 86 | ||
| 87 | ||
| 88 | shift | |
| 89 | done | |
.github/workflows/ci.yml +2
| @@ -37,6 +37,8 @@ jobs: | ||
| 37 | 37 | uses: mozilla-actions/sccache-action@v0.0.9 |
| 38 | 38 | - name: Check formatting |
| 39 | 39 | run: cargo +nightly fmt --all -- --check |
| 40 | - name: Check imports formatting | |
| 41 | run: find src -name '*.rs' | xargs ./.github/workflows/check-imports-format.sh | |
| 40 | 42 | - name: Check Clippy |
| 41 | 43 | if: matrix.platform == 'ubuntu-latest' |
| 42 | 44 | uses: giraffate/clippy-action@v1 |
src/base.rs +44 −106
| @@ -1,112 +1,50 @@ | ||
| 1 | 1 | //! # Common types and utilities |
| 2 | 2 | //! |
| 3 | 3 | //! The types defined here get used throughout iamb. |
| 4 | use std::borrow::Cow; | |
| 4 | ||
| 5 | 5 | use std::collections::hash_map::{Entry, IntoIter}; |
| 6 | use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; | |
| 7 | use std::convert::TryFrom; | |
| 8 | use std::fmt::{self, Display}; | |
| 9 | use std::hash::Hash; | |
| 10 | use std::sync::Arc; | |
| 11 | use std::time::{Duration, Instant}; | |
| 6 | use std::collections::{BTreeSet, HashSet}; | |
| 12 | 7 | |
| 13 | 8 | use emojis::Emoji; |
| 14 | ||
| 15 | 9 | use matrix_sdk::Client; |
| 16 | use matrix_sdk::encryption::verification::VerificationRequest; | |
| 17 | use matrix_sdk::ruma::room::{AllowRule, Restricted}; | |
| 18 | use ratatui::{ | |
| 19 | buffer::Buffer, | |
| 20 | layout::{Alignment, Rect}, | |
| 21 | text::{Line, Span}, | |
| 22 | widgets::{Paragraph, Widget}, | |
| 10 | use matrix_sdk::ruma::events::reaction::ReactionEvent; | |
| 11 | use matrix_sdk::ruma::events::relation::Replacement; | |
| 12 | use matrix_sdk::ruma::events::room::encrypted::RoomEncryptedEvent; | |
| 13 | use matrix_sdk::ruma::events::room::message::{ | |
| 14 | RoomMessageEvent, | |
| 15 | RoomMessageEventContentWithoutRelation, | |
| 23 | 16 | }; |
| 24 | use serde::{ | |
| 25 | Deserialize, | |
| 26 | Deserializer, | |
| 27 | Serialize, | |
| 28 | Serializer, | |
| 29 | de::Error as SerdeError, | |
| 30 | de::Visitor, | |
| 17 | use matrix_sdk::ruma::events::room::redaction::{ | |
| 18 | OriginalSyncRoomRedactionEvent, | |
| 19 | SyncRoomRedactionEvent, | |
| 31 | 20 | }; |
| 32 | use tokio::sync::Mutex as AsyncMutex; | |
| 33 | use url::Url; | |
| 34 | ||
| 35 | use matrix_sdk::{ | |
| 36 | RoomState as MatrixRoomState, | |
| 37 | room::Room as MatrixRoom, | |
| 38 | ruma::{ | |
| 39 | EventId, | |
| 40 | OwnedEventId, | |
| 41 | OwnedMxcUri, | |
| 42 | OwnedRoomAliasId, | |
| 43 | OwnedRoomId, | |
| 44 | OwnedRoomOrAliasId, | |
| 45 | OwnedTransactionId, | |
| 46 | OwnedUserId, | |
| 47 | RoomId, | |
| 48 | RoomVersionId, | |
| 49 | UserId, | |
| 50 | events::{ | |
| 51 | AnySyncStateEvent, | |
| 52 | MessageLikeEvent, | |
| 53 | OriginalMessageLikeEvent, | |
| 54 | reaction::ReactionEvent, | |
| 55 | receipt::ReceiptThread, | |
| 56 | relation::{Replacement, Thread}, | |
| 57 | room::MediaSource, | |
| 58 | room::encrypted::RoomEncryptedEvent, | |
| 59 | room::message::{ | |
| 60 | MessageType, | |
| 61 | OriginalRoomMessageEvent, | |
| 62 | Relation, | |
| 63 | RoomMessageEvent, | |
| 64 | RoomMessageEventContent, | |
| 65 | RoomMessageEventContentWithoutRelation, | |
| 66 | }, | |
| 67 | room::redaction::{OriginalSyncRoomRedactionEvent, SyncRoomRedactionEvent}, | |
| 68 | sticker::{StickerEvent, StickerEventContent}, | |
| 69 | tag::{TagName, Tags}, | |
| 70 | }, | |
| 71 | presence::PresenceState, | |
| 72 | profile::{ProfileFieldName, ProfileFieldValue}, | |
| 73 | room::JoinRule, | |
| 74 | }, | |
| 75 | }; | |
| 76 | ||
| 77 | use modalkit::{ | |
| 78 | actions::Action, | |
| 79 | editing::{ | |
| 80 | application::{ | |
| 81 | ApplicationAction, | |
| 82 | ApplicationContentId, | |
| 83 | ApplicationError, | |
| 84 | ApplicationInfo, | |
| 85 | ApplicationStore, | |
| 86 | ApplicationWindowId, | |
| 87 | }, | |
| 88 | completion::CompletionMap, | |
| 89 | context::EditContext, | |
| 90 | store::Store, | |
| 91 | }, | |
| 92 | env::vim::{ | |
| 93 | command::{CommandContext, VimCommand, VimCommandMachine}, | |
| 94 | keybindings::VimMachine, | |
| 95 | }, | |
| 96 | errors::{UIError, UIResult}, | |
| 97 | key::TerminalKey, | |
| 98 | keybindings::SequenceStatus, | |
| 99 | prelude::{CommandType, MoveDir1D, WordStyle}, | |
| 21 | use matrix_sdk::ruma::events::sticker::{StickerEvent, StickerEventContent}; | |
| 22 | use matrix_sdk::ruma::events::{MessageLikeEvent, OriginalMessageLikeEvent}; | |
| 23 | use matrix_sdk::ruma::presence::PresenceState; | |
| 24 | use matrix_sdk::ruma::room::{AllowRule, Restricted}; | |
| 25 | use matrix_sdk::ruma::{OwnedMxcUri, OwnedTransactionId, RoomVersionId}; | |
| 26 | use modalkit::editing::application::{ | |
| 27 | ApplicationAction, | |
| 28 | ApplicationContentId, | |
| 29 | ApplicationError, | |
| 30 | ApplicationInfo, | |
| 31 | ApplicationStore, | |
| 32 | ApplicationWindowId, | |
| 100 | 33 | }; |
| 34 | use modalkit::editing::completion::CompletionMap; | |
| 35 | use modalkit::editing::context::EditContext; | |
| 36 | use modalkit::editing::store::Store; | |
| 37 | use modalkit::env::vim::command::{CommandContext, VimCommand, VimCommandMachine}; | |
| 38 | use modalkit::env::vim::keybindings::VimMachine; | |
| 39 | use modalkit::errors::UIResult; | |
| 40 | use modalkit::keybindings::SequenceStatus; | |
| 41 | use serde::de::Error as SerdeError; | |
| 42 | use serde::de::Visitor; | |
| 43 | use serde::{Deserialize, Deserializer, Serialize, Serializer}; | |
| 44 | use tokio::sync::Mutex as AsyncMutex; | |
| 101 | 45 | |
| 102 | use crate::preview::PreviewKind; | |
| 103 | use crate::{ | |
| 104 | config::ApplicationSettings, | |
| 105 | message::{Message, MessageEvent, MessageKey, MessageTimeStamp, Messages}, | |
| 106 | notifications::NotificationHandle, | |
| 107 | preview::PreviewManager, | |
| 108 | worker::Requester, | |
| 109 | }; | |
| 46 | use crate::notifications::NotificationHandle; | |
| 47 | use crate::prelude::*; | |
| 110 | 48 | |
| 111 | 49 | /// The set of characters used in different Matrix IDs. |
| 112 | 50 | pub const MATRIX_ID_WORD: WordStyle = WordStyle::CharSet(is_mxid_char); |
| @@ -2307,20 +2245,20 @@ impl ApplicationInfo for IambInfo { | ||
| 2307 | 2245 | |
| 2308 | 2246 | #[cfg(test)] |
| 2309 | 2247 | pub mod tests { |
| 2248 | use super::*; | |
| 2249 | ||
| 2310 | 2250 | use std::iter::FromIterator as _; |
| 2311 | 2251 | |
| 2312 | use super::*; | |
| 2313 | use crate::config::user_style_from_color; | |
| 2314 | use crate::tests::*; | |
| 2315 | use matrix_sdk::ruma::{ | |
| 2316 | MilliSecondsSinceUnixEpoch, | |
| 2317 | events::{reaction::ReactionEventContent, relation::Annotation}, | |
| 2318 | owned_event_id, | |
| 2319 | }; | |
| 2252 | use matrix_sdk::ruma::events::reaction::ReactionEventContent; | |
| 2253 | use matrix_sdk::ruma::events::relation::Annotation; | |
| 2254 | use matrix_sdk::ruma::{MilliSecondsSinceUnixEpoch, owned_event_id}; | |
| 2320 | 2255 | use pretty_assertions::assert_eq; |
| 2321 | 2256 | use ratatui::style::Color; |
| 2322 | 2257 | use serde_json::{Map, Value}; |
| 2323 | 2258 | |
| 2259 | use crate::config::user_style_from_color; | |
| 2260 | use crate::tests::*; | |
| 2261 | ||
| 2324 | 2262 | fn create_reaction_event( |
| 2325 | 2263 | content: &ReactionEventContent, |
| 2326 | 2264 | event_id: &str, |
src/commands.rs +5 −21
| @@ -2,42 +2,25 @@ | ||
| 2 | 2 | //! |
| 3 | 3 | //! The command-bar commands are set up here, and iamb-specific commands are defined here. See |
| 4 | 4 | //! [modalkit::env::vim::command] for additional Vim commands we pull in. |
| 5 | use std::{convert::TryFrom, str::FromStr as _}; | |
| 6 | ||
| 7 | use matrix_sdk::ruma::{ | |
| 8 | OwnedMxcUri, | |
| 9 | OwnedRoomOrAliasId, | |
| 10 | OwnedUserId, | |
| 11 | RoomVersionId, | |
| 12 | events::tag::TagName, | |
| 13 | profile::{ProfileFieldName, ProfileFieldValue}, | |
| 14 | }; | |
| 15 | 5 | |
| 16 | use modalkit::{ | |
| 17 | commands::{CommandError, CommandResult, CommandStep}, | |
| 18 | env::vim::command::{CommandContext, CommandDescription, OptionType}, | |
| 19 | prelude::{MoveDir1D, OpenTarget}, | |
| 20 | }; | |
| 6 | use matrix_sdk::ruma::{OwnedMxcUri, RoomVersionId}; | |
| 7 | use modalkit::commands::{CommandError, CommandResult, CommandStep}; | |
| 8 | use modalkit::env::vim::command::{CommandContext, CommandDescription, OptionType}; | |
| 21 | 9 | |
| 22 | 10 | use crate::base::{ |
| 23 | 11 | CreateRoomFlags, |
| 24 | 12 | CreateRoomType, |
| 25 | 13 | DownloadFlags, |
| 26 | 14 | HomeserverAction, |
| 27 | IambAction, | |
| 28 | IambId, | |
| 29 | 15 | IambJoinRule, |
| 30 | 16 | KeysAction, |
| 31 | 17 | MemberUpdateAction, |
| 32 | MessageAction, | |
| 33 | 18 | ProgramCommand, |
| 34 | 19 | ProgramCommands, |
| 35 | RoomAction, | |
| 36 | 20 | RoomField, |
| 37 | SendAction, | |
| 38 | SpaceAction, | |
| 39 | 21 | VerifyAction, |
| 40 | 22 | }; |
| 23 | use crate::prelude::*; | |
| 41 | 24 | |
| 42 | 25 | type ProgContext = CommandContext; |
| 43 | 26 | type ProgResult = CommandResult<ProgramCommand>; |
| @@ -1156,6 +1139,7 @@ pub fn setup_commands() -> ProgramCommands { | ||
| 1156 | 1139 | #[cfg(test)] |
| 1157 | 1140 | mod tests { |
| 1158 | 1141 | use super::*; |
| 1142 | ||
| 1159 | 1143 | use matrix_sdk::ruma::{owned_room_id, user_id}; |
| 1160 | 1144 | use modalkit::actions::WindowAction; |
| 1161 | 1145 | use modalkit::editing::context::EditContext; |
src/completions.rs +20 −39
| @@ -1,39 +1,19 @@ | ||
| 1 | 1 | //! Tab completions for iamb |
| 2 | use std::borrow::Cow; | |
| 3 | use std::str::FromStr; | |
| 4 | ||
| 5 | use modalkit::{ | |
| 6 | editing::{ | |
| 7 | completion::{Completer, complete_path}, | |
| 8 | cursor::Cursor, | |
| 9 | rope::EditRope, | |
| 10 | }, | |
| 11 | env::vim::command::CommandDescription, | |
| 12 | prelude::{ | |
| 13 | CommandType, | |
| 14 | Count, | |
| 15 | CursorMovements, | |
| 16 | CursorMovementsContext, | |
| 17 | MoveDir1D, | |
| 18 | MoveType, | |
| 19 | WordStyle, | |
| 20 | }, | |
| 21 | }; | |
| 22 | ||
| 23 | use crate::base::{ChatStore, IambBufferId, IambInfo, MATRIX_ID_WORD, RoomFocus}; | |
| 2 | ||
| 3 | use modalkit::editing::completion::{Completer, complete_path}; | |
| 4 | use modalkit::editing::cursor::Cursor; | |
| 5 | use modalkit::env::vim::command::CommandDescription; | |
| 6 | ||
| 7 | use crate::base::MATRIX_ID_WORD; | |
| 8 | use crate::prelude::*; | |
| 24 | 9 | |
| 25 | 10 | mod parse { |
| 26 | use nom::{ | |
| 27 | IResult, | |
| 28 | Input, | |
| 29 | OutputMode, | |
| 30 | Parser, | |
| 31 | branch::alt, | |
| 32 | bytes::complete::{escaped_transform, is_not, tag}, | |
| 33 | character::complete::{char, space0, space1}, | |
| 34 | combinator::{cut, eof, opt, value}, | |
| 35 | error::{ErrorKind, ParseError}, | |
| 36 | }; | |
| 11 | use nom::branch::alt; | |
| 12 | use nom::bytes::complete::{escaped_transform, is_not, tag}; | |
| 13 | use nom::character::complete::{char, space0, space1}; | |
| 14 | use nom::combinator::{cut, eof, opt, value}; | |
| 15 | use nom::error::{ErrorKind, ParseError}; | |
| 16 | use nom::{IResult, Input, OutputMode, Parser}; | |
| 37 | 17 | |
| 38 | 18 | fn parse_text(input: &str) -> IResult<&str, String> { |
| 39 | 19 | if input.is_empty() { |
| @@ -782,14 +762,15 @@ impl Completer<IambInfo> for IambCompleter { | ||
| 782 | 762 | #[cfg(test)] |
| 783 | 763 | pub mod tests { |
| 784 | 764 | use super::*; |
| 785 | use crate::{ | |
| 786 | base::{ProgramCommand, ProgramCommands}, | |
| 787 | commands::add_iamb_commands, | |
| 788 | tests::*, | |
| 789 | }; | |
| 790 | use modalkit::{commands::CommandResult, env::vim::command::CommandContext}; | |
| 765 | ||
| 766 | use modalkit::commands::CommandResult; | |
| 767 | use modalkit::env::vim::command::CommandContext; | |
| 791 | 768 | use pretty_assertions::assert_eq; |
| 792 | 769 | |
| 770 | use crate::base::{ProgramCommand, ProgramCommands}; | |
| 771 | use crate::commands::add_iamb_commands; | |
| 772 | use crate::tests::*; | |
| 773 | ||
| 793 | 774 | #[tokio::test] |
| 794 | 775 | async fn test_complete_msgbar() { |
| 795 | 776 | let store = mock_store().await; |
src/config.rs +13 −27
| @@ -1,44 +1,28 @@ | ||
| 1 | 1 | //! # Logic for loading and validating application configuration |
| 2 | use std::borrow::Cow; | |
| 2 | ||
| 3 | 3 | use std::collections::hash_map::DefaultHasher; |
| 4 | use std::collections::{BTreeMap, HashMap}; | |
| 5 | 4 | use std::env; |
| 6 | use std::fmt; | |
| 7 | 5 | use std::fs::File; |
| 8 | 6 | use std::hash::{Hash, Hasher}; |
| 9 | use std::io::{BufReader, BufWriter, Write}; | |
| 10 | use std::path::{Path, PathBuf}; | |
| 7 | use std::io::{BufReader, BufWriter, Write as _}; | |
| 11 | 8 | use std::process; |
| 12 | use std::str::FromStr; | |
| 13 | 9 | |
| 14 | 10 | use clap::Parser; |
| 15 | 11 | use matrix_sdk::EncryptionState; |
| 16 | 12 | use matrix_sdk::authentication::matrix::MatrixSession; |
| 17 | 13 | use matrix_sdk::media::MediaRetentionPolicy; |
| 18 | 14 | use matrix_sdk::reqwest::header::{HeaderMap, HeaderValue}; |
| 19 | use matrix_sdk::ruma::{OwnedDeviceId, OwnedRoomAliasId, OwnedRoomId, OwnedUserId, UserId}; | |
| 20 | use ratatui::layout::Size; | |
| 21 | use ratatui::style::{Color, Modifier as StyleModifier, Style}; | |
| 22 | use ratatui::text::Span; | |
| 15 | use matrix_sdk::ruma::OwnedDeviceId; | |
| 16 | use modalkit::env::vim::VimMode; | |
| 17 | use modalkit::keybindings::InputKey; | |
| 23 | 18 | use ratatui_image::FilterType; |
| 24 | 19 | use ratatui_image::picker::ProtocolType; |
| 25 | use serde::{Deserialize, Deserializer, Serialize, de::Error as SerdeError, de::Visitor}; | |
| 26 | use url::Url; | |
| 20 | use serde::de::Error as SerdeError; | |
| 21 | use serde::de::Visitor; | |
| 22 | use serde::{Deserialize, Deserializer, Serialize}; | |
| 27 | 23 | |
| 28 | use modalkit::env::vim::VimMode; | |
| 29 | use modalkit::key::TerminalKey; | |
| 30 | use modalkit::keybindings::InputKey; | |
| 31 | use modalkit::prelude::Axis; | |
| 32 | ||
| 33 | use super::base::{ | |
| 34 | IambError, | |
| 35 | IambId, | |
| 36 | RoomInfo, | |
| 37 | SortColumn, | |
| 38 | SortFieldRoom, | |
| 39 | SortFieldUser, | |
| 40 | SortOrder, | |
| 41 | }; | |
| 24 | use crate::base::{SortColumn, SortFieldRoom, SortFieldUser, SortOrder}; | |
| 25 | use crate::prelude::*; | |
| 42 | 26 | |
| 43 | 27 | type Macros = HashMap<VimModes, HashMap<Keys, Keys>>; |
| 44 | 28 | |
| @@ -1426,9 +1410,11 @@ impl ApplicationSettings { | ||
| 1426 | 1410 | #[cfg(test)] |
| 1427 | 1411 | mod tests { |
| 1428 | 1412 | use super::*; |
| 1429 | use matrix_sdk::ruma::user_id; | |
| 1413 | ||
| 1430 | 1414 | use std::convert::TryFrom; |
| 1431 | 1415 | |
| 1416 | use matrix_sdk::ruma::user_id; | |
| 1417 | ||
| 1432 | 1418 | #[test] |
| 1433 | 1419 | fn test_profile_name_invalid() { |
| 1434 | 1420 | assert_eq!(validate_profile_name(""), false); |
src/keybindings.rs +9 −12
| @@ -2,18 +2,15 @@ | ||
| 2 | 2 | //! |
| 3 | 3 | //! The keybindings are set up here. We define some iamb-specific keybindings, but the default Vim |
| 4 | 4 | //! keys come from [modalkit::env::vim::keybindings]. |
| 5 | use modalkit::{ | |
| 6 | actions::{InsertTextAction, MacroAction, WindowAction}, | |
| 7 | env::CommonKeyClass, | |
| 8 | env::vim::VimMode, | |
| 9 | env::vim::keybindings::{InputStep, VimBindings}, | |
| 10 | key::TerminalKey, | |
| 11 | keybindings::{EdgeEvent, EdgeRepeat, InputBindings}, | |
| 12 | prelude::*, | |
| 13 | }; | |
| 14 | ||
| 15 | use crate::base::{IambAction, IambInfo, Keybindings, MATRIX_ID_WORD}; | |
| 16 | use crate::config::{ApplicationSettings, Keys, SplitDirection}; | |
| 5 | use modalkit::actions::MacroAction; | |
| 6 | use modalkit::env::CommonKeyClass; | |
| 7 | use modalkit::env::vim::VimMode; | |
| 8 | use modalkit::env::vim::keybindings::{InputStep, VimBindings}; | |
| 9 | use modalkit::keybindings::{EdgeEvent, EdgeRepeat, InputBindings}; | |
| 10 | ||
| 11 | use crate::base::{Keybindings, MATRIX_ID_WORD}; | |
| 12 | use crate::config::{Keys, SplitDirection}; | |
| 13 | use crate::prelude::*; | |
| 17 | 14 | |
| 18 | 15 | pub type IambStep = InputStep<IambInfo>; |
| 19 | 16 | |
src/main.rs +45 −102
| @@ -16,61 +16,60 @@ | ||
| 16 | 16 | #![allow(clippy::needless_return)] |
| 17 | 17 | #![allow(clippy::result_large_err)] |
| 18 | 18 | #![allow(clippy::bool_assert_comparison)] |
| 19 | ||
| 19 | 20 | use std::collections::VecDeque; |
| 20 | use std::convert::TryFrom; | |
| 21 | use std::fmt::Display; | |
| 22 | 21 | use std::fs::{File, create_dir_all}; |
| 23 | 22 | use std::io::{BufWriter, Stdout, Write, stdout}; |
| 24 | use std::ops::DerefMut; | |
| 25 | 23 | use std::process; |
| 26 | use std::sync::Arc; | |
| 27 | use std::sync::atomic::{AtomicUsize, Ordering}; | |
| 28 | use std::time::{Duration, Instant}; | |
| 24 | use std::sync::atomic::AtomicUsize; | |
| 29 | 25 | |
| 30 | 26 | use clap::{CommandFactory, Parser}; |
| 31 | use matrix_sdk::ruma::UserId; | |
| 32 | 27 | use matrix_sdk::ruma::api::error::ErrorKind; |
| 33 | use matrix_sdk::ruma::profile::{ProfileFieldName, ProfileFieldValue}; | |
| 34 | 28 | use matrix_sdk_crypto::encrypt_room_key_export; |
| 35 | use modalkit::keybindings::InputBindings; | |
| 29 | use modalkit::actions::{Commandable, TabAction, TabContainer, TabCount, WindowContainer}; | |
| 30 | use modalkit::crossterm::cursor::{SetCursorStyle, Show as CursorShow}; | |
| 31 | use modalkit::crossterm::event::{ | |
| 32 | DisableBracketedPaste, | |
| 33 | DisableFocusChange, | |
| 34 | DisableMouseCapture, | |
| 35 | EnableBracketedPaste, | |
| 36 | EnableFocusChange, | |
| 37 | EnableMouseCapture, | |
| 38 | Event, | |
| 39 | KeyEventKind, | |
| 40 | KeyboardEnhancementFlags, | |
| 41 | MouseEventKind, | |
| 42 | PopKeyboardEnhancementFlags, | |
| 43 | PushKeyboardEnhancementFlags, | |
| 44 | poll, | |
| 45 | read, | |
| 46 | }; | |
| 47 | use modalkit::crossterm::terminal::{EnterAlternateScreen, LeaveAlternateScreen, SetTitle}; | |
| 48 | use modalkit::crossterm::{self, execute}; | |
| 49 | use modalkit::editing::key::KeyManager; | |
| 50 | use modalkit::editing::store::Store; | |
| 51 | use modalkit::keybindings::dialog::Pager; | |
| 52 | use modalkit::keybindings::{BindingMachine, InputBindings}; | |
| 53 | use modalkit::ui::FocusList; | |
| 54 | use modalkit_ratatui::cmdbar::CommandBarState; | |
| 55 | use modalkit_ratatui::screen::{Screen, ScreenState, TabbedLayoutDescription}; | |
| 56 | use modalkit_ratatui::windows::{WindowLayoutDescription, WindowLayoutState}; | |
| 57 | use modalkit_ratatui::{TerminalExtOps, Window}; | |
| 36 | 58 | use rand::RngExt as _; |
| 37 | 59 | use rand::distr::Alphanumeric; |
| 60 | use ratatui::Terminal; | |
| 61 | use ratatui::backend::CrosstermBackend; | |
| 38 | 62 | use temp_dir::TempDir; |
| 39 | 63 | use tokio::sync::Mutex as AsyncMutex; |
| 40 | 64 | use tracing::Level; |
| 41 | 65 | use tracing_subscriber::{EnvFilter, FmtSubscriber}; |
| 42 | 66 | |
| 43 | use modalkit::crossterm::{ | |
| 44 | self, | |
| 45 | cursor::{SetCursorStyle, Show as CursorShow}, | |
| 46 | event::{ | |
| 47 | DisableBracketedPaste, | |
| 48 | DisableFocusChange, | |
| 49 | DisableMouseCapture, | |
| 50 | EnableBracketedPaste, | |
| 51 | EnableFocusChange, | |
| 52 | EnableMouseCapture, | |
| 53 | Event, | |
| 54 | KeyEventKind, | |
| 55 | KeyboardEnhancementFlags, | |
| 56 | MouseEventKind, | |
| 57 | PopKeyboardEnhancementFlags, | |
| 58 | PushKeyboardEnhancementFlags, | |
| 59 | poll, | |
| 60 | read, | |
| 61 | }, | |
| 62 | execute, | |
| 63 | terminal::{EnterAlternateScreen, LeaveAlternateScreen, SetTitle}, | |
| 64 | }; | |
| 65 | ||
| 66 | use ratatui::{ | |
| 67 | Terminal, | |
| 68 | backend::CrosstermBackend, | |
| 69 | layout::Rect, | |
| 70 | style::{Color, Modifier, Style}, | |
| 71 | text::Span, | |
| 72 | widgets::Paragraph, | |
| 73 | }; | |
| 67 | use crate::base::{HomeserverAction, KeysAction}; | |
| 68 | use crate::completions::IambCompleter; | |
| 69 | use crate::config::Iamb; | |
| 70 | use crate::prelude::*; | |
| 71 | use crate::windows::IambWindow; | |
| 72 | use crate::worker::{ClientWorker, LoginStyle, create_room}; | |
| 74 | 73 | |
| 75 | 74 | mod base; |
| 76 | 75 | mod commands; |
| @@ -79,72 +78,16 @@ mod config; | ||
| 79 | 78 | mod keybindings; |
| 80 | 79 | mod message; |
| 81 | 80 | mod notifications; |
| 81 | mod prelude; | |
| 82 | 82 | mod preview; |
| 83 | 83 | mod sled_export; |
| 84 | 84 | mod util; |
| 85 | mod verifications; | |
| 85 | 86 | mod windows; |
| 86 | 87 | mod worker; |
| 87 | 88 | |
| 88 | 89 | #[cfg(test)] |
| 89 | 90 | mod tests; |
| 90 | mod verifications; | |
| 91 | ||
| 92 | use crate::{ | |
| 93 | base::{ | |
| 94 | AsyncProgramStore, | |
| 95 | ChatStore, | |
| 96 | HomeserverAction, | |
| 97 | IambAction, | |
| 98 | IambError, | |
| 99 | IambId, | |
| 100 | IambInfo, | |
| 101 | IambResult, | |
| 102 | KeysAction, | |
| 103 | ProgramAction, | |
| 104 | ProgramContext, | |
| 105 | ProgramStore, | |
| 106 | }, | |
| 107 | completions::IambCompleter, | |
| 108 | config::{ApplicationSettings, Iamb}, | |
| 109 | windows::IambWindow, | |
| 110 | worker::{ClientWorker, LoginStyle, Requester, create_room}, | |
| 111 | }; | |
| 112 | ||
| 113 | use modalkit::{ | |
| 114 | actions::{ | |
| 115 | Action, | |
| 116 | Commandable, | |
| 117 | Editable, | |
| 118 | EditorAction, | |
| 119 | InsertTextAction, | |
| 120 | Jumpable, | |
| 121 | Promptable, | |
| 122 | Scrollable, | |
| 123 | TabAction, | |
| 124 | TabContainer, | |
| 125 | TabCount, | |
| 126 | WindowAction, | |
| 127 | WindowContainer, | |
| 128 | }, | |
| 129 | editing::{context::Resolve, key::KeyManager, store::Store}, | |
| 130 | errors::{EditError, UIError}, | |
| 131 | key::TerminalKey, | |
| 132 | keybindings::{ | |
| 133 | BindingMachine, | |
| 134 | dialog::{Pager, PromptYesNo}, | |
| 135 | }, | |
| 136 | prelude::*, | |
| 137 | ui::FocusList, | |
| 138 | }; | |
| 139 | ||
| 140 | use modalkit_ratatui::{ | |
| 141 | TerminalCursor, | |
| 142 | TerminalExtOps, | |
| 143 | Window, | |
| 144 | cmdbar::CommandBarState, | |
| 145 | screen::{Screen, ScreenState, TabbedLayoutDescription}, | |
| 146 | windows::{WindowLayoutDescription, WindowLayoutState}, | |
| 147 | }; | |
| 148 | 91 | |
| 149 | 92 | fn config_tab_to_desc( |
| 150 | 93 | layout: config::WindowLayout, |
| @@ -334,9 +277,9 @@ impl Application { | ||
| 334 | 277 | .show_dialog(dialogstr) |
| 335 | 278 | .show_mode(modestr) |
| 336 | 279 | .borders(true) |
| 337 | .border_style(Style::default().add_modifier(Modifier::DIM)) | |
| 338 | .tab_style(Style::default().add_modifier(Modifier::DIM)) | |
| 339 | .tab_style_focused(Style::default().remove_modifier(Modifier::DIM)) | |
| 280 | .border_style(Style::default().add_modifier(StyleModifier::DIM)) | |
| 281 | .tab_style(Style::default().add_modifier(StyleModifier::DIM)) | |
| 282 | .tab_style_focused(Style::default().remove_modifier(StyleModifier::DIM)) | |
| 340 | 283 | .focus(focused); |
| 341 | 284 | f.render_stateful_widget(screen, area, sstate); |
| 342 | 285 | |
| @@ -1225,7 +1168,7 @@ fn main() { | ||
| 1225 | 1168 | .worker_threads(2) |
| 1226 | 1169 | .thread_name_fn(|| { |
| 1227 | 1170 | static ATOMIC_ID: AtomicUsize = AtomicUsize::new(0); |
| 1228 | let id = ATOMIC_ID.fetch_add(1, Ordering::SeqCst); | |
| 1171 | let id = ATOMIC_ID.fetch_add(1, std::sync::atomic::Ordering::SeqCst); | |
| 1229 | 1172 | format!("iamb-worker-{id}") |
| 1230 | 1173 | }) |
| 1231 | 1174 | .build() |
src/message/compose.rs +10 −16
| @@ -1,22 +1,16 @@ | ||
| 1 | 1 | //! Code for converting composed messages into content to send to the homeserver. |
| 2 | use comrak::{markdown_to_html, options::Options}; | |
| 3 | use nom::{ | |
| 4 | IResult, | |
| 5 | Parser as _, | |
| 6 | branch::alt, | |
| 7 | bytes::complete::tag, | |
| 8 | character::complete::space0, | |
| 9 | combinator::value, | |
| 10 | }; | |
| 11 | ||
| 12 | use matrix_sdk::ruma::events::room::message::{ | |
| 13 | EmoteMessageEventContent, | |
| 14 | MessageType, | |
| 15 | RoomMessageEventContent, | |
| 16 | TextMessageEventContent, | |
| 17 | }; | |
| 2 | ||
| 3 | use comrak::markdown_to_html; | |
| 4 | use comrak::options::Options; | |
| 5 | use matrix_sdk::ruma::events::room::message::{EmoteMessageEventContent, TextMessageEventContent}; | |
| 6 | use nom::branch::alt; | |
| 7 | use nom::bytes::complete::tag; | |
| 8 | use nom::character::complete::space0; | |
| 9 | use nom::combinator::value; | |
| 10 | use nom::{IResult, Parser as _}; | |
| 18 | 11 | |
| 19 | 12 | use crate::config::MarkupFormat; |
| 13 | use crate::prelude::*; | |
| 20 | 14 | |
| 21 | 15 | #[derive(Clone, Debug, Default)] |
| 22 | 16 | enum SlashCommand { |
src/message/html.rs +13 −28
| @@ -10,35 +10,18 @@ | ||
| 10 | 10 | //! |
| 11 | 11 | //! This isn't as important for iamb, since it isn't a browser environment, but we do still map |
| 12 | 12 | //! input onto an enum of the safe list of tags to keep it easy to understand and process. |
| 13 | use std::borrow::Cow; | |
| 14 | use std::ops::Deref; | |
| 15 | 13 | |
| 16 | 14 | use css_color_parser::Color as CssColor; |
| 15 | use html5ever::driver::{ParseOpts, parse_fragment}; | |
| 16 | use html5ever::interface::{Attribute, QualName}; | |
| 17 | use html5ever::tendril::{StrTendril, TendrilSink}; | |
| 18 | use html5ever::{local_name, ns}; | |
| 17 | 19 | use markup5ever_rcdom::{Handle, NodeData, RcDom}; |
| 18 | use matrix_sdk::ruma::{OwnedRoomAliasId, OwnedRoomId, OwnedUserId}; | |
| 19 | use unicode_segmentation::UnicodeSegmentation; | |
| 20 | use url::Url; | |
| 21 | ||
| 22 | use html5ever::{ | |
| 23 | driver::{ParseOpts, parse_fragment}, | |
| 24 | interface::{Attribute, QualName}, | |
| 25 | local_name, | |
| 26 | ns, | |
| 27 | tendril::{StrTendril, TendrilSink}, | |
| 28 | }; | |
| 29 | ||
| 30 | use ratatui::{ | |
| 31 | layout::Alignment, | |
| 32 | style::{Color, Modifier as StyleModifier, Style}, | |
| 33 | symbols::line, | |
| 34 | text::{Line, Span, Text}, | |
| 35 | }; | |
| 36 | ||
| 37 | use crate::{ | |
| 38 | config::ApplicationSettings, | |
| 39 | message::printer::TextPrinter, | |
| 40 | util::{join_cell_text, space_text}, | |
| 41 | }; | |
| 20 | use ratatui::symbols::line; | |
| 21 | ||
| 22 | use crate::message::printer::TextPrinter; | |
| 23 | use crate::prelude::*; | |
| 24 | use crate::util::{join_cell_text, space_text}; | |
| 42 | 25 | |
| 43 | 26 | const QUOTE_COLOR: Color = Color::Indexed(236); |
| 44 | 27 | |
| @@ -844,11 +827,13 @@ pub fn parse_matrix_html(s: &str) -> StyleTree { | ||
| 844 | 827 | #[cfg(test)] |
| 845 | 828 | pub mod tests { |
| 846 | 829 | use super::*; |
| 847 | use crate::tests::mock_settings; | |
| 848 | use crate::util::space_span; | |
| 830 | ||
| 849 | 831 | use pretty_assertions::assert_eq; |
| 850 | 832 | use unicode_width::UnicodeWidthStr; |
| 851 | 833 | |
| 834 | use crate::tests::mock_settings; | |
| 835 | use crate::util::space_span; | |
| 836 | ||
| 852 | 837 | #[test] |
| 853 | 838 | fn test_header() { |
| 854 | 839 | let settings = mock_settings(); |
src/message/mod.rs +36 −72
| @@ -1,75 +1,41 @@ | ||
| 1 | 1 | //! # Room Messages |
| 2 | use std::borrow::Cow; | |
| 3 | use std::cmp::{Ord, Ordering, PartialOrd}; | |
| 4 | use std::collections::BTreeMap; | |
| 2 | ||
| 3 | use std::cmp::{Ord, PartialOrd}; | |
| 5 | 4 | use std::collections::hash_map::DefaultHasher; |
| 6 | use std::convert::{TryFrom, TryInto}; | |
| 7 | use std::fmt::{self, Display}; | |
| 5 | use std::convert::TryInto; | |
| 8 | 6 | use std::hash::{Hash, Hasher}; |
| 9 | use std::ops::{Deref, DerefMut}; | |
| 10 | 7 | |
| 11 | 8 | use chrono::{DateTime, Local as LocalTz}; |
| 12 | 9 | use humansize::{DECIMAL, format_size}; |
| 13 | 10 | use matrix_sdk::ruma::OwnedTransactionId; |
| 14 | use matrix_sdk::ruma::events::receipt::ReceiptThread; | |
| 15 | use matrix_sdk::ruma::events::room::MediaSource; | |
| 11 | use matrix_sdk::ruma::UInt; | |
| 12 | use matrix_sdk::ruma::events::RedactedUnsigned; | |
| 13 | use matrix_sdk::ruma::events::room::encrypted::{ | |
| 14 | OriginalRoomEncryptedEvent, | |
| 15 | RedactedRoomEncryptedEvent, | |
| 16 | RoomEncryptedEvent, | |
| 17 | }; | |
| 16 | 18 | use matrix_sdk::ruma::events::room::message::RoomMessageEventContentWithoutRelation; |
| 19 | use matrix_sdk::ruma::events::room::message::{ | |
| 20 | FormattedBody, | |
| 21 | MessageFormat, | |
| 22 | RedactedRoomMessageEvent, | |
| 23 | RoomMessageEvent, | |
| 24 | }; | |
| 25 | use matrix_sdk::ruma::events::room::redaction::SyncRoomRedactionEvent; | |
| 17 | 26 | use matrix_sdk::ruma::events::sticker::{OriginalStickerEvent, RedactedStickerEvent, StickerEvent}; |
| 18 | 27 | use matrix_sdk::ruma::events::{AnyRedactionEvent, MessageLikeEvent}; |
| 19 | 28 | use matrix_sdk::send_queue::SendHandle; |
| 20 | use ratatui::layout::Size; | |
| 21 | use ratatui::style::Color; | |
| 22 | use ratatui_image::sliced::SlicedProtocol; | |
| 23 | use unicode_width::UnicodeWidthStr; | |
| 24 | ||
| 25 | use matrix_sdk::ruma::{ | |
| 26 | EventId, | |
| 27 | MilliSecondsSinceUnixEpoch, | |
| 28 | OwnedEventId, | |
| 29 | OwnedUserId, | |
| 30 | UInt, | |
| 31 | events::{ | |
| 32 | AnySyncStateEvent, | |
| 33 | RedactedUnsigned, | |
| 34 | relation::Thread, | |
| 35 | room::{ | |
| 36 | encrypted::{ | |
| 37 | OriginalRoomEncryptedEvent, | |
| 38 | RedactedRoomEncryptedEvent, | |
| 39 | RoomEncryptedEvent, | |
| 40 | }, | |
| 41 | message::{ | |
| 42 | FormattedBody, | |
| 43 | MessageFormat, | |
| 44 | MessageType, | |
| 45 | OriginalRoomMessageEvent, | |
| 46 | RedactedRoomMessageEvent, | |
| 47 | Relation, | |
| 48 | RoomMessageEvent, | |
| 49 | RoomMessageEventContent, | |
| 50 | }, | |
| 51 | redaction::SyncRoomRedactionEvent, | |
| 52 | }, | |
| 53 | }, | |
| 54 | }; | |
| 55 | ||
| 56 | use ratatui::{ | |
| 57 | style::{Modifier as StyleModifier, Style}, | |
| 58 | symbols::line::THICK_VERTICAL, | |
| 59 | text::{Line, Span, Text}, | |
| 60 | }; | |
| 61 | ||
| 62 | 29 | use modalkit::editing::cursor::Cursor; |
| 63 | use modalkit::prelude::*; | |
| 30 | use ratatui::symbols::line::THICK_VERTICAL; | |
| 31 | use ratatui_image::sliced::SlicedProtocol; | |
| 64 | 32 | |
| 65 | 33 | use crate::base::MessageEdits; |
| 66 | use crate::preview::{ImageStatus, PreviewKind, PreviewManager}; | |
| 67 | use crate::{ | |
| 68 | base::RoomInfo, | |
| 69 | config::ApplicationSettings, | |
| 70 | message::html::{StyleTree, parse_matrix_html}, | |
| 71 | util::{replace_emojis_in_str, space, space_span, take_width, wrapped_text}, | |
| 72 | }; | |
| 34 | use crate::message::html::{StyleTree, parse_matrix_html}; | |
| 35 | use crate::message::state::{body_cow_state, html_state}; | |
| 36 | use crate::prelude::*; | |
| 37 | use crate::preview::ImageStatus; | |
| 38 | use crate::util::{replace_emojis_in_str, space, space_span, take_width, wrapped_text}; | |
| 73 | 39 | |
| 74 | 40 | mod compose; |
| 75 | 41 | mod html; |
| @@ -77,8 +43,7 @@ mod printer; | ||
| 77 | 43 | mod state; |
| 78 | 44 | |
| 79 | 45 | pub use self::compose::{text_to_message, text_to_text_message_event_content}; |
| 80 | use self::state::{body_cow_state, html_state}; | |
| 81 | pub use html::TreeGenState; | |
| 46 | pub use self::html::TreeGenState; | |
| 82 | 47 | |
| 83 | 48 | type ProtocolPreview<'a> = (&'a SlicedProtocol, u16, u16); |
| 84 | 49 | |
| @@ -1473,20 +1438,19 @@ impl Display for Message { | ||
| 1473 | 1438 | |
| 1474 | 1439 | #[cfg(test)] |
| 1475 | 1440 | pub mod tests { |
| 1476 | use matrix_sdk::ruma::events::room::{ | |
| 1477 | ImageInfo, | |
| 1478 | message::{ | |
| 1479 | AudioInfo, | |
| 1480 | AudioMessageEventContent, | |
| 1481 | FileInfo, | |
| 1482 | FileMessageEventContent, | |
| 1483 | ImageMessageEventContent, | |
| 1484 | VideoInfo, | |
| 1485 | VideoMessageEventContent, | |
| 1486 | }, | |
| 1441 | use super::*; | |
| 1442 | ||
| 1443 | use matrix_sdk::ruma::events::room::ImageInfo; | |
| 1444 | use matrix_sdk::ruma::events::room::message::{ | |
| 1445 | AudioInfo, | |
| 1446 | AudioMessageEventContent, | |
| 1447 | FileInfo, | |
| 1448 | FileMessageEventContent, | |
| 1449 | ImageMessageEventContent, | |
| 1450 | VideoInfo, | |
| 1451 | VideoMessageEventContent, | |
| 1487 | 1452 | }; |
| 1488 | 1453 | |
| 1489 | use super::*; | |
| 1490 | 1454 | use crate::tests::*; |
| 1491 | 1455 | |
| 1492 | 1456 | #[test] |
src/message/printer.rs +3 −8
| @@ -3,15 +3,9 @@ | ||
| 3 | 3 | //! The [TextPrinter] handles wrapping stylized text and inserting spaces for padding at the end of |
| 4 | 4 | //! lines to make concatenation work right (e.g., combining table cells after wrapping their |
| 5 | 5 | //! contents). |
| 6 | use std::borrow::Cow; | |
| 7 | 6 | |
| 8 | use ratatui::layout::Alignment; | |
| 9 | use ratatui::style::Style; | |
| 10 | use ratatui::text::{Line, Span, Text}; | |
| 11 | use unicode_segmentation::UnicodeSegmentation; | |
| 12 | use unicode_width::UnicodeWidthStr; | |
| 13 | ||
| 14 | use crate::config::{ApplicationSettings, TunableValues}; | |
| 7 | use crate::config::TunableValues; | |
| 8 | use crate::prelude::*; | |
| 15 | 9 | use crate::util::{ |
| 16 | 10 | replace_emojis_in_line, |
| 17 | 11 | replace_emojis_in_span, |
| @@ -295,6 +289,7 @@ impl<'a> TextPrinter<'a> { | ||
| 295 | 289 | #[cfg(test)] |
| 296 | 290 | pub mod tests { |
| 297 | 291 | use super::*; |
| 292 | ||
| 298 | 293 | use crate::tests::mock_settings; |
| 299 | 294 | |
| 300 | 295 | #[test] |
src/message/state.rs +6 −16
| @@ -1,20 +1,10 @@ | ||
| 1 | 1 | //! Code for displaying state events. |
| 2 | use std::borrow::Cow; | |
| 3 | use std::str::FromStr; | |
| 4 | ||
| 5 | use matrix_sdk::ruma::{ | |
| 6 | OwnedRoomId, | |
| 7 | UserId, | |
| 8 | events::{ | |
| 9 | AnyStateEventContentChange, | |
| 10 | AnySyncStateEvent, | |
| 11 | StateEventContentChange, | |
| 12 | room::member::MembershipChange, | |
| 13 | }, | |
| 14 | }; | |
| 15 | ||
| 16 | use super::html::{StyleTree, StyleTreeNode}; | |
| 17 | use ratatui::style::{Modifier as StyleModifier, Style}; | |
| 2 | ||
| 3 | use matrix_sdk::ruma::events::room::member::MembershipChange; | |
| 4 | use matrix_sdk::ruma::events::{AnyStateEventContentChange, StateEventContentChange}; | |
| 5 | ||
| 6 | use crate::message::html::{StyleTree, StyleTreeNode}; | |
| 7 | use crate::prelude::*; | |
| 18 | 8 | |
| 19 | 9 | fn bold(s: impl Into<Cow<'static, str>>) -> StyleTreeNode { |
| 20 | 10 | let bold = Style::default().add_modifier(StyleModifier::BOLD); |
src/notifications.rs +11 −18
| @@ -1,25 +1,18 @@ | ||
| 1 | 1 | use std::time::SystemTime; |
| 2 | 2 | |
| 3 | use matrix_sdk::{ | |
| 4 | Client, | |
| 5 | EncryptionState, | |
| 6 | deserialized_responses::RawAnySyncOrStrippedTimelineEvent, | |
| 7 | notification_settings::{IsEncrypted, IsOneToOne, NotificationSettings, RoomNotificationMode}, | |
| 8 | room::Room as MatrixRoom, | |
| 9 | ruma::{ | |
| 10 | MilliSecondsSinceUnixEpoch, | |
| 11 | OwnedRoomId, | |
| 12 | RoomId, | |
| 13 | events::{AnyMessageLikeEventContent, AnySyncTimelineEvent, room::message::MessageType}, | |
| 14 | serde::Raw, | |
| 15 | }, | |
| 3 | use matrix_sdk::EncryptionState; | |
| 4 | use matrix_sdk::deserialized_responses::RawAnySyncOrStrippedTimelineEvent; | |
| 5 | use matrix_sdk::notification_settings::{ | |
| 6 | IsEncrypted, | |
| 7 | IsOneToOne, | |
| 8 | NotificationSettings, | |
| 9 | RoomNotificationMode, | |
| 16 | 10 | }; |
| 17 | use unicode_segmentation::UnicodeSegmentation; | |
| 11 | use matrix_sdk::ruma::events::{AnyMessageLikeEventContent, AnySyncTimelineEvent}; | |
| 12 | use matrix_sdk::ruma::serde::Raw; | |
| 18 | 13 | |
| 19 | use crate::{ | |
| 20 | base::{AsyncProgramStore, IambError, IambResult, ProgramStore}, | |
| 21 | config::{ApplicationSettings, NotifyVia}, | |
| 22 | }; | |
| 14 | use crate::config::NotifyVia; | |
| 15 | use crate::prelude::*; | |
| 23 | 16 | |
| 24 | 17 | const IAMB_XDG_NAME: &str = match option_env!("IAMB_XDG_NAME") { |
| 25 | 18 | None => "iamb", |
src/prelude.rs added +90
| @@ -0,0 +1,90 @@ | ||
| 1 | pub use std::borrow::Cow; | |
| 2 | pub use std::cmp::Ordering; | |
| 3 | pub use std::collections::{BTreeMap, HashMap}; | |
| 4 | pub use std::convert::TryFrom; | |
| 5 | pub use std::fmt::{self, Display}; | |
| 6 | pub use std::ops::{Deref, DerefMut}; | |
| 7 | pub use std::path::{Path, PathBuf}; | |
| 8 | pub use std::str::FromStr; | |
| 9 | pub use std::sync::Arc; | |
| 10 | pub use std::time::{Duration, Instant}; | |
| 11 | ||
| 12 | pub use matrix_sdk::ruma::events::AnySyncStateEvent; | |
| 13 | pub use matrix_sdk::ruma::events::receipt::ReceiptThread; | |
| 14 | pub use matrix_sdk::ruma::events::relation::Thread; | |
| 15 | pub use matrix_sdk::ruma::events::room::MediaSource; | |
| 16 | pub use matrix_sdk::ruma::events::room::message::{ | |
| 17 | MessageType, | |
| 18 | OriginalRoomMessageEvent, | |
| 19 | Relation, | |
| 20 | RoomMessageEventContent, | |
| 21 | }; | |
| 22 | pub use matrix_sdk::ruma::events::tag::{TagName, Tags}; | |
| 23 | pub use matrix_sdk::ruma::{ | |
| 24 | EventId, | |
| 25 | MilliSecondsSinceUnixEpoch, | |
| 26 | OwnedEventId, | |
| 27 | OwnedRoomAliasId, | |
| 28 | OwnedRoomId, | |
| 29 | OwnedRoomOrAliasId, | |
| 30 | OwnedUserId, | |
| 31 | RoomId, | |
| 32 | UserId, | |
| 33 | profile::{ProfileFieldName, ProfileFieldValue}, | |
| 34 | room::JoinRule, | |
| 35 | }; | |
| 36 | pub use matrix_sdk::{ | |
| 37 | Client, | |
| 38 | RoomState as MatrixRoomState, | |
| 39 | encryption::verification::VerificationRequest, | |
| 40 | room::Room as MatrixRoom, | |
| 41 | }; | |
| 42 | pub use modalkit::actions::{ | |
| 43 | Action, | |
| 44 | Editable, | |
| 45 | EditorAction, | |
| 46 | InsertTextAction, | |
| 47 | Jumpable, | |
| 48 | PromptAction, | |
| 49 | Promptable, | |
| 50 | Scrollable, | |
| 51 | WindowAction, | |
| 52 | }; | |
| 53 | pub use modalkit::editing::{completion::CompletionList, context::Resolve, rope::EditRope}; | |
| 54 | pub use modalkit::errors::{EditError, EditResult, UIError}; | |
| 55 | pub use modalkit::key::TerminalKey; | |
| 56 | pub use modalkit::keybindings::dialog::PromptYesNo; | |
| 57 | pub use modalkit::prelude::*; | |
| 58 | pub use modalkit_ratatui::{TermOffset, TerminalCursor, WindowOps}; | |
| 59 | pub use ratatui::buffer::Buffer; | |
| 60 | pub use ratatui::layout::{Alignment, Rect, Size}; | |
| 61 | pub use ratatui::style::{Color, Modifier as StyleModifier, Style}; | |
| 62 | pub use ratatui::text::{Line, Span, Text}; | |
| 63 | pub use ratatui::widgets::{Paragraph, StatefulWidget, Widget}; | |
| 64 | pub use unicode_segmentation::UnicodeSegmentation; | |
| 65 | pub use unicode_width::UnicodeWidthStr; | |
| 66 | pub use url::Url; | |
| 67 | ||
| 68 | pub use crate::base::{ | |
| 69 | AsyncProgramStore, | |
| 70 | ChatStore, | |
| 71 | IambAction, | |
| 72 | IambBufferId, | |
| 73 | IambError, | |
| 74 | IambId, | |
| 75 | IambInfo, | |
| 76 | IambResult, | |
| 77 | MessageAction, | |
| 78 | ProgramAction, | |
| 79 | ProgramContext, | |
| 80 | ProgramStore, | |
| 81 | RoomAction, | |
| 82 | RoomFocus, | |
| 83 | RoomInfo, | |
| 84 | SendAction, | |
| 85 | SpaceAction, | |
| 86 | }; | |
| 87 | pub use crate::config::ApplicationSettings; | |
| 88 | pub use crate::message::{Message, MessageEvent, MessageKey, MessageTimeStamp, Messages}; | |
| 89 | pub use crate::preview::{PreviewKind, PreviewManager}; | |
| 90 | pub use crate::worker::Requester; | |
src/preview.rs +6 −14
| @@ -1,20 +1,12 @@ | ||
| 1 | use std::{collections::HashMap, sync::Arc}; | |
| 2 | ||
| 3 | use matrix_sdk::{ | |
| 4 | Media, | |
| 5 | media::{MediaFormat, MediaRequestParameters, UniqueKey}, | |
| 6 | ruma::events::room::MediaSource, | |
| 7 | }; | |
| 8 | use ratatui::layout::Size; | |
| 1 | use matrix_sdk::Media; | |
| 2 | use matrix_sdk::media::{MediaFormat, MediaRequestParameters, UniqueKey}; | |
| 3 | use ratatui_image::picker::Picker; | |
| 9 | 4 | use ratatui_image::sliced::SlicedProtocol; |
| 10 | use ratatui_image::{FilterType, Resize, picker::Picker}; | |
| 5 | use ratatui_image::{FilterType, Resize}; | |
| 11 | 6 | use tokio::sync::Semaphore; |
| 12 | 7 | |
| 13 | use crate::{ | |
| 14 | base::{AsyncProgramStore, IambError}, | |
| 15 | config::{ApplicationSettings, ImagePreviewValues}, | |
| 16 | worker::Requester, | |
| 17 | }; | |
| 8 | use crate::config::ImagePreviewValues; | |
| 9 | use crate::prelude::*; | |
| 18 | 10 | |
| 19 | 11 | pub enum ImageStatus { |
| 20 | 12 | Queued(Size), |
src/sled_export.rs +3 −3
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | //! time to upgrade off of pre-0.0.9 versions. |
| 11 | 11 | //! |
| 12 | 12 | //! [sled]: https://docs.rs/sled/0.34.7/sled/index.html |
| 13 | use sled::{Config, IVec}; | |
| 14 | use std::path::Path; | |
| 15 | 13 | |
| 16 | use crate::base::IambError; | |
| 17 | 14 | use matrix_sdk_crypto::olm::{ExportedRoomKey, InboundGroupSession, PickledInboundGroupSession}; |
| 15 | use sled::{Config, IVec}; | |
| 16 | ||
| 17 | use crate::prelude::*; | |
| 18 | 18 | |
| 19 | 19 | #[derive(Debug, thiserror::Error)] |
| 20 | 20 | pub enum SledMigrationError { |
src/tests.rs +6 −24
| @@ -1,32 +1,14 @@ | ||
| 1 | use std::path::PathBuf; | |
| 2 | use std::{collections::HashMap, iter::FromIterator as _}; | |
| 3 | ||
| 4 | use matrix_sdk::ruma::{ | |
| 5 | EventId, | |
| 6 | OwnedEventId, | |
| 7 | OwnedRoomId, | |
| 8 | OwnedUserId, | |
| 9 | RoomId, | |
| 10 | UInt, | |
| 11 | event_id, | |
| 12 | events::room::message::RoomMessageEventContent, | |
| 13 | server_name, | |
| 14 | user_id, | |
| 15 | }; | |
| 16 | use matrix_sdk::ruma::{MilliSecondsSinceUnixEpoch, assign}; | |
| 1 | use std::iter::FromIterator as _; | |
| 17 | 2 | |
| 18 | 3 | use lazy_static::lazy_static; |
| 19 | use ratatui::style::{Color, Style}; | |
| 4 | use matrix_sdk::ruma::assign; | |
| 5 | use matrix_sdk::ruma::{UInt, event_id, server_name, user_id}; | |
| 20 | 6 | use serde_json::{Map, Value}; |
| 21 | 7 | use tokio::sync::mpsc::unbounded_channel; |
| 22 | 8 | |
| 23 | use crate::message::MessageTimeStamp; | |
| 24 | use crate::{ | |
| 25 | base::{ChatStore, EventLocation, ProgramStore, RoomInfo}, | |
| 26 | config::*, | |
| 27 | message::{Message, MessageEvent, MessageKey, Messages}, | |
| 28 | worker::Requester, | |
| 29 | }; | |
| 9 | use crate::base::EventLocation; | |
| 10 | use crate::config::*; | |
| 11 | use crate::prelude::*; | |
| 30 | 12 | |
| 31 | 13 | const TEST_ROOM1_ALIAS: &str = "#room1:example.com"; |
| 32 | 14 | |
src/util.rs +1 −5
| @@ -1,12 +1,8 @@ | ||
| 1 | 1 | //! # Utility functions |
| 2 | use std::borrow::Cow; | |
| 3 | 2 | |
| 4 | 3 | use regex::{Regex, RegexBuilder}; |
| 5 | use unicode_segmentation::UnicodeSegmentation; | |
| 6 | use unicode_width::UnicodeWidthStr; | |
| 7 | 4 | |
| 8 | use ratatui::style::Style; | |
| 9 | use ratatui::text::{Line, Span, Text}; | |
| 5 | use crate::prelude::*; | |
| 10 | 6 | |
| 11 | 7 | pub fn split_cow(cow: Cow<'_, str>, idx: usize) -> (Cow<'_, str>, Cow<'_, str>) { |
| 12 | 8 | match cow { |
src/verifications.rs +4 −10
| @@ -1,15 +1,9 @@ | ||
| 1 | use matrix_sdk::Client; | |
| 2 | use matrix_sdk::encryption::verification::{ | |
| 3 | Verification, | |
| 4 | VerificationRequest, | |
| 5 | VerificationRequestState, | |
| 6 | }; | |
| 1 | use matrix_sdk::encryption::verification::{Verification, VerificationRequestState}; | |
| 2 | use matrix_sdk::ruma::OwnedDeviceId; | |
| 7 | 3 | use matrix_sdk::ruma::events::key::verification::VerificationMethod; |
| 8 | use matrix_sdk::ruma::{OwnedDeviceId, OwnedUserId, UserId}; | |
| 9 | use modalkit::errors::UIError; | |
| 10 | use modalkit::prelude::{EditInfo, InfoMessage}; | |
| 11 | 4 | |
| 12 | use crate::base::{AsyncProgramStore, IambError, IambResult, ProgramStore, VerifyAction}; | |
| 5 | use crate::base::VerifyAction; | |
| 6 | use crate::prelude::*; | |
| 13 | 7 | |
| 14 | 8 | const SUPPORTED_METHODS: [VerificationMethod; 3] = [ |
| 15 | 9 | // Emoji verification |
src/windows/mod.rs +16 −77
| @@ -6,84 +6,22 @@ | ||
| 6 | 6 | //! Additionally, some of the iamb commands delegate behaviour to the current UI element. For |
| 7 | 7 | //! example, [sending messages][crate::base::SendAction] delegate to the [room window][RoomState], |
| 8 | 8 | //! where we have the message bar and room ID easily accessible and resettable. |
| 9 | use std::cmp::{Ord, Ordering}; | |
| 10 | use std::fmt::{self, Display}; | |
| 11 | use std::ops::Deref; | |
| 12 | use std::sync::Arc; | |
| 13 | use std::time::{Duration, Instant}; | |
| 14 | ||
| 15 | use matrix_sdk::{ | |
| 16 | RoomState as MatrixRoomState, | |
| 17 | room::{Room as MatrixRoom, RoomMember}, | |
| 18 | ruma::{ | |
| 19 | OwnedRoomAliasId, | |
| 20 | OwnedRoomId, | |
| 21 | RoomAliasId, | |
| 22 | RoomId, | |
| 23 | events::room::member::MembershipState, | |
| 24 | events::tag::{TagName, Tags}, | |
| 25 | }, | |
| 26 | }; | |
| 27 | ||
| 28 | use ratatui::{ | |
| 29 | buffer::Buffer, | |
| 30 | layout::{Alignment, Rect}, | |
| 31 | style::{Color, Modifier as StyleModifier, Style}, | |
| 32 | text::{Line, Span, Text}, | |
| 33 | widgets::StatefulWidget, | |
| 34 | }; | |
| 35 | ||
| 36 | use modalkit::{ | |
| 37 | actions::{ | |
| 38 | Action, | |
| 39 | Editable, | |
| 40 | EditorAction, | |
| 41 | Jumpable, | |
| 42 | PromptAction, | |
| 43 | Promptable, | |
| 44 | Scrollable, | |
| 45 | WindowAction, | |
| 46 | }, | |
| 47 | editing::completion::CompletionList, | |
| 48 | errors::{EditError, EditResult, UIError}, | |
| 49 | prelude::*, | |
| 50 | }; | |
| 51 | ||
| 52 | use modalkit_ratatui::{ | |
| 53 | TermOffset, | |
| 54 | TerminalCursor, | |
| 55 | Window, | |
| 56 | WindowOps, | |
| 57 | list::{List, ListCursor, ListItem, ListState}, | |
| 58 | }; | |
| 59 | ||
| 60 | use crate::base::{ | |
| 61 | ChatStore, | |
| 62 | IambBufferId, | |
| 63 | IambError, | |
| 64 | IambId, | |
| 65 | IambInfo, | |
| 66 | IambResult, | |
| 67 | MessageAction, | |
| 68 | ProgramAction, | |
| 69 | ProgramContext, | |
| 70 | ProgramStore, | |
| 71 | RoomAction, | |
| 72 | SendAction, | |
| 73 | SortColumn, | |
| 74 | SortFieldRoom, | |
| 75 | SortFieldUser, | |
| 76 | SortOrder, | |
| 77 | SpaceAction, | |
| 78 | UnreadInfo, | |
| 79 | }; | |
| 80 | use crate::windows::room::room_command; | |
| 81 | ||
| 82 | use self::room::RoomState; | |
| 83 | use self::verify::VerifyItem; | |
| 84 | use self::welcome::WelcomeState; | |
| 85 | use crate::message::MessageTimeStamp; | |
| 9 | ||
| 10 | use std::cmp::Ord; | |
| 11 | use std::fmt::{self}; | |
| 12 | ||
| 86 | 13 | use feruca::Collator; |
| 14 | use matrix_sdk::room::RoomMember; | |
| 15 | use matrix_sdk::ruma::RoomAliasId; | |
| 16 | use matrix_sdk::ruma::events::room::member::MembershipState; | |
| 17 | use modalkit_ratatui::Window; | |
| 18 | use modalkit_ratatui::list::{List, ListCursor, ListItem, ListState}; | |
| 19 | ||
| 20 | use crate::base::{SortColumn, SortFieldRoom, SortFieldUser, SortOrder, UnreadInfo}; | |
| 21 | use crate::prelude::*; | |
| 22 | use crate::windows::room::{RoomState, room_command}; | |
| 23 | use crate::windows::verify::VerifyItem; | |
| 24 | use crate::windows::welcome::WelcomeState; | |
| 87 | 25 | |
| 88 | 26 | pub mod room; |
| 89 | 27 | pub mod verify; |
| @@ -1587,6 +1525,7 @@ impl Promptable<ProgramContext, ProgramStore, IambInfo> for MemberItem { | ||
| 1587 | 1525 | #[cfg(test)] |
| 1588 | 1526 | mod tests { |
| 1589 | 1527 | use super::*; |
| 1528 | ||
| 1590 | 1529 | use matrix_sdk::ruma::{MilliSecondsSinceUnixEpoch, room_alias_id, server_name}; |
| 1591 | 1530 | |
| 1592 | 1531 | #[derive(Debug, Eq, PartialEq)] |
src/windows/room/chat.rs +18 −87
| @@ -1,106 +1,37 @@ | ||
| 1 | 1 | //! Window for Matrix rooms |
| 2 | use std::borrow::Cow; | |
| 3 | 2 | use std::convert::TryInto; |
| 4 | 3 | use std::ffi::{OsStr, OsString}; |
| 5 | 4 | use std::fs; |
| 6 | use std::path::{Path, PathBuf}; | |
| 5 | use std::process::Command; | |
| 7 | 6 | |
| 8 | 7 | use edit::Builder; |
| 9 | 8 | use edit::edit_with_builder as external_edit; |
| 9 | use matrix_sdk::RoomState as MatrixRoomState; | |
| 10 | use matrix_sdk::attachment::AttachmentConfig; | |
| 10 | 11 | use matrix_sdk::attachment::{AttachmentInfo, BaseImageInfo}; |
| 12 | use matrix_sdk::media::{MediaFormat, MediaRequestParameters}; | |
| 11 | 13 | use matrix_sdk::room::reply::{EnforceThread, Reply}; |
| 14 | use matrix_sdk::ruma::events::reaction::ReactionEventContent; | |
| 15 | use matrix_sdk::ruma::events::relation::{Annotation, Replacement}; | |
| 16 | use matrix_sdk::ruma::events::room::message::{AddMentions, ForwardThread, ReplyWithinThread}; | |
| 17 | use matrix_sdk::send_queue::RoomSendQueueError; | |
| 18 | use modalkit::editing::history::{self, HistoryList}; | |
| 12 | 19 | use modalkit::editing::store::RegisterError; |
| 13 | use std::process::Command; | |
| 14 | use tokio; | |
| 15 | use url::Url; | |
| 16 | ||
| 17 | use matrix_sdk::{ | |
| 18 | RoomState, | |
| 19 | attachment::AttachmentConfig, | |
| 20 | media::{MediaFormat, MediaRequestParameters}, | |
| 21 | room::Room as MatrixRoom, | |
| 22 | ruma::{ | |
| 23 | OwnedEventId, | |
| 24 | OwnedRoomId, | |
| 25 | RoomId, | |
| 26 | events::reaction::ReactionEventContent, | |
| 27 | events::relation::{Annotation, Replacement}, | |
| 28 | events::room::message::{ | |
| 29 | AddMentions, | |
| 30 | ForwardThread, | |
| 31 | MessageType, | |
| 32 | OriginalRoomMessageEvent, | |
| 33 | Relation, | |
| 34 | ReplyWithinThread, | |
| 35 | }, | |
| 36 | }, | |
| 37 | send_queue::RoomSendQueueError, | |
| 38 | }; | |
| 39 | ||
| 40 | use ratatui::{ | |
| 41 | buffer::Buffer, | |
| 42 | layout::Rect, | |
| 43 | prelude::Stylize, | |
| 44 | text::{Line, Span}, | |
| 45 | widgets::{Paragraph, StatefulWidget, Widget}, | |
| 46 | }; | |
| 47 | ||
| 48 | use modalkit::keybindings::dialog::{Dialog, MultiChoice, MultiChoiceItem, PromptYesNo}; | |
| 20 | use modalkit::keybindings::dialog::{Dialog, MultiChoice, MultiChoiceItem}; | |
| 21 | use modalkit_ratatui::PromptActions; | |
| 22 | use modalkit_ratatui::textbox::{TextBox, TextBoxState}; | |
| 23 | use ratatui::prelude::Stylize; | |
| 49 | 24 | |
| 50 | use modalkit_ratatui::{ | |
| 51 | PromptActions, | |
| 52 | TerminalCursor, | |
| 53 | WindowOps, | |
| 54 | textbox::{TextBox, TextBoxState}, | |
| 55 | }; | |
| 56 | ||
| 57 | use modalkit::actions::{ | |
| 58 | Action, | |
| 59 | Editable, | |
| 60 | EditorAction, | |
| 61 | Jumpable, | |
| 62 | PromptAction, | |
| 63 | Promptable, | |
| 64 | Scrollable, | |
| 65 | }; | |
| 66 | use modalkit::editing::{ | |
| 67 | completion::CompletionList, | |
| 68 | context::Resolve, | |
| 69 | history::{self, HistoryList}, | |
| 70 | rope::EditRope, | |
| 71 | }; | |
| 72 | use modalkit::errors::{EditError, EditResult, UIError}; | |
| 73 | use modalkit::prelude::*; | |
| 74 | ||
| 75 | use crate::base::{ | |
| 76 | DownloadFlags, | |
| 77 | EchoLocation, | |
| 78 | IambAction, | |
| 79 | IambBufferId, | |
| 80 | IambError, | |
| 81 | IambInfo, | |
| 82 | IambResult, | |
| 83 | MessageAction, | |
| 84 | ProgramAction, | |
| 85 | ProgramContext, | |
| 86 | ProgramStore, | |
| 87 | RoomFocus, | |
| 88 | RoomInfo, | |
| 89 | SendAction, | |
| 90 | }; | |
| 91 | ||
| 92 | use crate::config::{ApplicationSettings, EncryptionIndicatorLocation}; | |
| 25 | use crate::base::{DownloadFlags, EchoLocation}; | |
| 26 | use crate::config::EncryptionIndicatorLocation; | |
| 93 | 27 | use crate::message::{ |
| 94 | MessageEvent, | |
| 95 | 28 | MessageId, |
| 96 | MessageKey, | |
| 97 | 29 | TreeGenState, |
| 98 | 30 | text_to_message, |
| 99 | 31 | text_to_text_message_event_content, |
| 100 | 32 | }; |
| 101 | use crate::worker::Requester; | |
| 102 | ||
| 103 | use super::scrollback::{Scrollback, ScrollbackState}; | |
| 33 | use crate::prelude::*; | |
| 34 | use crate::windows::room::scrollback::{Scrollback, ScrollbackState}; | |
| 104 | 35 | |
| 105 | 36 | /// State needed for rendering [Chat]. |
| 106 | 37 | pub struct ChatState { |
| @@ -151,7 +82,7 @@ impl ChatState { | ||
| 151 | 82 | return Err(IambError::NotJoined); |
| 152 | 83 | }; |
| 153 | 84 | |
| 154 | if room.state() == RoomState::Joined { | |
| 85 | if room.state() == MatrixRoomState::Joined { | |
| 155 | 86 | Ok(room) |
| 156 | 87 | } else { |
| 157 | 88 | Err(IambError::NotJoined) |
src/windows/room/mod.rs +16 −69
| @@ -1,78 +1,25 @@ | ||
| 1 | 1 | //! # Windows for Matrix rooms and spaces |
| 2 | 2 | use std::collections::HashSet; |
| 3 | 3 | |
| 4 | use matrix_sdk::{ | |
| 5 | RoomDisplayName, | |
| 6 | RoomState as MatrixRoomState, | |
| 7 | notification_settings::RoomNotificationMode, | |
| 8 | room::Room as MatrixRoom, | |
| 9 | ruma::{ | |
| 10 | OwnedEventId, | |
| 11 | OwnedRoomAliasId, | |
| 12 | OwnedUserId, | |
| 13 | RoomId, | |
| 14 | api::{ | |
| 15 | client::room::upgrade_room::v3::Request as UpgradeRoomRequest, | |
| 16 | error::ErrorKind as ClientApiErrorKind, | |
| 17 | }, | |
| 18 | events::{ | |
| 19 | room::{ | |
| 20 | canonical_alias::RoomCanonicalAliasEventContent, | |
| 21 | history_visibility::{HistoryVisibility, RoomHistoryVisibilityEventContent}, | |
| 22 | name::RoomNameEventContent, | |
| 23 | topic::RoomTopicEventContent, | |
| 24 | }, | |
| 25 | tag::{TagInfo, Tags}, | |
| 26 | }, | |
| 27 | room::{AllowRule, JoinRule, Restricted as JoinRestrictions}, | |
| 28 | }, | |
| 29 | }; | |
| 30 | ||
| 31 | use ratatui::{ | |
| 32 | buffer::Buffer, | |
| 33 | layout::{Alignment, Rect}, | |
| 34 | style::{Modifier as StyleModifier, Style}, | |
| 35 | text::{Line, Span, Text}, | |
| 36 | widgets::{Paragraph, StatefulWidget, Widget}, | |
| 4 | use matrix_sdk::RoomDisplayName; | |
| 5 | use matrix_sdk::notification_settings::RoomNotificationMode; | |
| 6 | use matrix_sdk::ruma::api::client::room::upgrade_room::v3::Request as UpgradeRoomRequest; | |
| 7 | use matrix_sdk::ruma::api::error::ErrorKind as ClientApiErrorKind; | |
| 8 | use matrix_sdk::ruma::events::room::canonical_alias::RoomCanonicalAliasEventContent; | |
| 9 | use matrix_sdk::ruma::events::room::history_visibility::{ | |
| 10 | HistoryVisibility, | |
| 11 | RoomHistoryVisibilityEventContent, | |
| 37 | 12 | }; |
| 13 | use matrix_sdk::ruma::events::room::name::RoomNameEventContent; | |
| 14 | use matrix_sdk::ruma::events::room::topic::RoomTopicEventContent; | |
| 15 | use matrix_sdk::ruma::events::tag::TagInfo; | |
| 16 | use matrix_sdk::ruma::room::{AllowRule, Restricted as JoinRestrictions}; | |
| 38 | 17 | |
| 39 | use modalkit::actions::{ | |
| 40 | Action, | |
| 41 | Editable, | |
| 42 | EditorAction, | |
| 43 | Jumpable, | |
| 44 | PromptAction, | |
| 45 | Promptable, | |
| 46 | Scrollable, | |
| 47 | WindowAction, | |
| 48 | }; | |
| 49 | use modalkit::errors::{EditResult, UIError}; | |
| 50 | use modalkit::prelude::*; | |
| 51 | use modalkit::{editing::completion::CompletionList, keybindings::dialog::PromptYesNo}; | |
| 52 | use modalkit_ratatui::{TermOffset, TerminalCursor, WindowOps}; | |
| 53 | ||
| 54 | use crate::base::{ | |
| 55 | IambAction, | |
| 56 | IambError, | |
| 57 | IambId, | |
| 58 | IambInfo, | |
| 59 | IambResult, | |
| 60 | MemberUpdateAction, | |
| 61 | MessageAction, | |
| 62 | ProgramAction, | |
| 63 | ProgramContext, | |
| 64 | ProgramStore, | |
| 65 | RoomAction, | |
| 66 | RoomField, | |
| 67 | SendAction, | |
| 68 | SpaceAction, | |
| 69 | }; | |
| 70 | ||
| 71 | use self::chat::ChatState; | |
| 72 | use self::space::{Space, SpaceState}; | |
| 18 | use crate::base::{MemberUpdateAction, RoomField}; | |
| 73 | 19 | use crate::config::EncryptionIndicatorLocation; |
| 74 | ||
| 75 | use std::convert::TryFrom; | |
| 20 | use crate::prelude::*; | |
| 21 | use crate::windows::room::chat::ChatState; | |
| 22 | use crate::windows::room::space::{Space, SpaceState}; | |
| 76 | 23 | |
| 77 | 24 | mod chat; |
| 78 | 25 | mod scrollback; |
src/windows/room/scrollback.rs +14 −51
| @@ -1,62 +1,23 @@ | ||
| 1 | 1 | //! Message scrollback |
| 2 | use ratatui_image::sliced::{SignedPosition, SlicedImage}; | |
| 3 | use regex::Regex; | |
| 4 | ||
| 5 | use matrix_sdk::ruma::{OwnedEventId, OwnedRoomId}; | |
| 6 | ||
| 7 | use modalkit_ratatui::{ScrollActions, TerminalCursor, WindowOps}; | |
| 8 | use ratatui::{ | |
| 9 | buffer::Buffer, | |
| 10 | layout::{Alignment, Rect}, | |
| 11 | style::{Modifier as StyleModifier, Style}, | |
| 12 | text::{Line, Span}, | |
| 13 | widgets::{Paragraph, StatefulWidget, Widget}, | |
| 14 | }; | |
| 15 | ||
| 16 | 2 | use modalkit::actions::{ |
| 17 | Action, | |
| 18 | 3 | CursorAction, |
| 19 | 4 | EditAction, |
| 20 | Editable, | |
| 21 | EditorAction, | |
| 22 | 5 | EditorActions, |
| 23 | 6 | HistoryAction, |
| 24 | InsertTextAction, | |
| 25 | Jumpable, | |
| 26 | PromptAction, | |
| 27 | Promptable, | |
| 28 | Scrollable, | |
| 29 | 7 | Searchable, |
| 30 | 8 | SelectionAction, |
| 31 | WindowAction, | |
| 32 | }; | |
| 33 | use modalkit::editing::{ | |
| 34 | completion::CompletionList, | |
| 35 | context::Resolve, | |
| 36 | cursor::{CursorGroup, CursorState}, | |
| 37 | history::HistoryList, | |
| 38 | rope::EditRope, | |
| 39 | store::{RegisterCell, RegisterPutFlags}, | |
| 40 | }; | |
| 41 | use modalkit::errors::{EditError, EditResult, UIError, UIResult}; | |
| 42 | use modalkit::prelude::*; | |
| 43 | ||
| 44 | use crate::{ | |
| 45 | base::{ | |
| 46 | IambBufferId, | |
| 47 | IambId, | |
| 48 | IambInfo, | |
| 49 | IambResult, | |
| 50 | ProgramContext, | |
| 51 | ProgramStore, | |
| 52 | RoomFetchStatus, | |
| 53 | RoomFocus, | |
| 54 | RoomInfo, | |
| 55 | }, | |
| 56 | config::ApplicationSettings, | |
| 57 | message::{Message, MessageCursor, MessageKey, Messages}, | |
| 58 | preview::{PreviewKind, PreviewManager}, | |
| 59 | 9 | }; |
| 10 | use modalkit::editing::cursor::{CursorGroup, CursorState}; | |
| 11 | use modalkit::editing::history::HistoryList; | |
| 12 | use modalkit::editing::store::{RegisterCell, RegisterPutFlags}; | |
| 13 | use modalkit::errors::UIResult; | |
| 14 | use modalkit_ratatui::ScrollActions; | |
| 15 | use ratatui_image::sliced::{SignedPosition, SlicedImage}; | |
| 16 | use regex::Regex; | |
| 17 | ||
| 18 | use crate::base::RoomFetchStatus; | |
| 19 | use crate::message::MessageCursor; | |
| 20 | use crate::prelude::*; | |
| 60 | 21 | |
| 61 | 22 | fn no_msgs() -> EditError<IambInfo> { |
| 62 | 23 | let msg = "No messages to select."; |
| @@ -1535,7 +1496,9 @@ impl StatefulWidget for Scrollback<'_> { | ||
| 1535 | 1496 | #[cfg(test)] |
| 1536 | 1497 | mod tests { |
| 1537 | 1498 | use super::*; |
| 1538 | use crate::{base::Need, tests::*}; | |
| 1499 | ||
| 1500 | use crate::base::Need; | |
| 1501 | use crate::tests::*; | |
| 1539 | 1502 | |
| 1540 | 1503 | #[tokio::test] |
| 1541 | 1504 | async fn test_search_messages() { |
src/windows/room/space.rs +2 −34
| @@ -1,43 +1,11 @@ | ||
| 1 | 1 | //! Window for Matrix spaces |
| 2 | use std::ops::{Deref, DerefMut}; | |
| 3 | use std::str::FromStr; | |
| 4 | use std::time::{Duration, Instant}; | |
| 5 | 2 | |
| 6 | 3 | use matrix_sdk::ruma::OwnedSpaceChildOrder; |
| 7 | 4 | use matrix_sdk::ruma::events::StateEventType; |
| 8 | 5 | use matrix_sdk::ruma::events::space::child::SpaceChildEventContent; |
| 9 | use matrix_sdk::{ | |
| 10 | room::Room as MatrixRoom, | |
| 11 | ruma::{OwnedRoomId, RoomId}, | |
| 12 | }; | |
| 13 | ||
| 14 | use modalkit::prelude::{EditInfo, InfoMessage}; | |
| 15 | use ratatui::{ | |
| 16 | buffer::Buffer, | |
| 17 | layout::Rect, | |
| 18 | style::{Color, Style}, | |
| 19 | text::{Line, Span, Text}, | |
| 20 | widgets::StatefulWidget, | |
| 21 | }; | |
| 22 | ||
| 23 | use modalkit_ratatui::{ | |
| 24 | TermOffset, | |
| 25 | TerminalCursor, | |
| 26 | WindowOps, | |
| 27 | list::{List, ListState}, | |
| 28 | }; | |
| 29 | ||
| 30 | use crate::base::{ | |
| 31 | IambBufferId, | |
| 32 | IambError, | |
| 33 | IambInfo, | |
| 34 | IambResult, | |
| 35 | ProgramContext, | |
| 36 | ProgramStore, | |
| 37 | RoomFocus, | |
| 38 | SpaceAction, | |
| 39 | }; | |
| 6 | use modalkit_ratatui::list::{List, ListState}; | |
| 40 | 7 | |
| 8 | use crate::prelude::*; | |
| 41 | 9 | use crate::windows::{RoomItem, RoomLikeItem, room_fields_cmp}; |
| 42 | 10 | |
| 43 | 11 | const SPACE_HIERARCHY_DEBOUNCE: Duration = Duration::from_secs(5); |
src/windows/verify.rs +2 −15
| @@ -1,23 +1,10 @@ | ||
| 1 | use std::cmp::Ordering; | |
| 2 | use std::fmt; | |
| 3 | ||
| 4 | use matrix_sdk::encryption::verification::{ | |
| 5 | Verification, | |
| 6 | VerificationRequest, | |
| 7 | VerificationRequestState, | |
| 8 | }; | |
| 1 | use matrix_sdk::encryption::verification::{Verification, VerificationRequestState}; | |
| 9 | 2 | use matrix_sdk::ruma::events::key::verification::VerificationMethod; |
| 10 | 3 | use matrix_sdk_crypto::matrix_sdk_qrcode::qrcode::render::unicode::Dense1x2; |
| 11 | 4 | use matrix_sdk_crypto::{QrVerificationState, SasState, format_emojis}; |
| 12 | ||
| 13 | use modalkit::actions::{PromptAction, Promptable}; | |
| 14 | use modalkit::errors::{EditError, EditResult}; | |
| 15 | use modalkit::prelude::ViewportContext; | |
| 16 | 5 | use modalkit_ratatui::list::{ListCursor, ListItem}; |
| 17 | use ratatui::style::{Color, Modifier as StyleModifier, Style}; | |
| 18 | use ratatui::text::{Line, Span, Text}; | |
| 19 | 6 | |
| 20 | use crate::base::{IambInfo, ProgramAction, ProgramContext, ProgramStore}; | |
| 7 | use crate::prelude::*; | |
| 21 | 8 | |
| 22 | 9 | const BLACK_ON_WHITE: Style = Style::new().fg(Color::Black).bg(Color::White); |
| 23 | 10 | |
src/windows/welcome.rs +2 −8
| @@ -1,14 +1,8 @@ | ||
| 1 | 1 | //! Welcome Window |
| 2 | use std::ops::{Deref, DerefMut}; | |
| 3 | 2 | |
| 4 | use ratatui::{buffer::Buffer, layout::Rect}; | |
| 3 | use modalkit_ratatui::textbox::TextBoxState; | |
| 5 | 4 | |
| 6 | use modalkit_ratatui::{TermOffset, TerminalCursor, WindowOps, textbox::TextBoxState}; | |
| 7 | ||
| 8 | use modalkit::editing::completion::CompletionList; | |
| 9 | use modalkit::prelude::*; | |
| 10 | ||
| 11 | use crate::base::{IambBufferId, IambInfo, IambResult, ProgramStore}; | |
| 5 | use crate::prelude::*; | |
| 12 | 6 | |
| 13 | 7 | const WELCOME_TEXT: &str = include_str!("welcome.md"); |
| 14 | 8 | |
src/worker.rs +58 −92
| @@ -2,116 +2,81 @@ | ||
| 2 | 2 | //! |
| 3 | 3 | //! The worker thread handles asynchronous work, and can receive messages from the main thread that |
| 4 | 4 | //! block on a reply from the async worker. |
| 5 | use std::collections::HashMap; | |
| 6 | use std::convert::TryFrom; | |
| 5 | ||
| 7 | 6 | use std::fmt::{Debug, Formatter}; |
| 8 | use std::ops::DerefMut; | |
| 9 | use std::str::FromStr; | |
| 10 | use std::sync::Arc; | |
| 11 | 7 | use std::sync::mpsc::{Receiver, SyncSender, sync_channel}; |
| 12 | use std::time::{Duration, Instant}; | |
| 13 | 8 | |
| 14 | use futures::{StreamExt, stream::FuturesUnordered}; | |
| 9 | use futures::StreamExt; | |
| 10 | use futures::stream::FuturesUnordered; | |
| 15 | 11 | use gethostname::gethostname; |
| 12 | use matrix_sdk::authentication::matrix::MatrixSession; | |
| 13 | use matrix_sdk::config::{RequestConfig, SyncSettings}; | |
| 14 | use matrix_sdk::encryption::{BackupDownloadStrategy, EncryptionSettings}; | |
| 15 | use matrix_sdk::event_handler::Ctx; | |
| 16 | use matrix_sdk::room::{Messages as MatrixMessages, MessagesOptions, RoomMember}; | |
| 17 | use matrix_sdk::ruma::api::client::filter::{ | |
| 18 | FilterDefinition, | |
| 19 | LazyLoadOptions, | |
| 20 | RoomEventFilter, | |
| 21 | RoomFilter, | |
| 22 | }; | |
| 23 | use matrix_sdk::ruma::api::client::room::Visibility; | |
| 24 | use matrix_sdk::ruma::api::client::room::create_room::v3::{ | |
| 25 | CreationContent, | |
| 26 | Request as CreateRoomRequest, | |
| 27 | }; | |
| 28 | use matrix_sdk::ruma::api::client::space::get_hierarchy::v1::Request as SpaceHierarchyRequest; | |
| 29 | use matrix_sdk::ruma::assign; | |
| 16 | 30 | use matrix_sdk::ruma::events::key::verification::ready::{ |
| 17 | 31 | OriginalSyncKeyVerificationReadyEvent, |
| 18 | 32 | ToDeviceKeyVerificationReadyEvent, |
| 19 | 33 | }; |
| 20 | use matrix_sdk_base::RoomStateFilter; | |
| 21 | use ratatui::layout::Size; | |
| 22 | use ratatui_image::picker::Picker; | |
| 23 | use tokio::sync::Semaphore; | |
| 24 | use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender, unbounded_channel}; | |
| 25 | use tokio::task::JoinHandle; | |
| 26 | use tracing::{Instrument as _, error, warn}; | |
| 27 | use url::Url; | |
| 28 | ||
| 34 | use matrix_sdk::ruma::events::key::verification::request::ToDeviceKeyVerificationRequestEvent; | |
| 35 | use matrix_sdk::ruma::events::key::verification::start::{ | |
| 36 | OriginalSyncKeyVerificationStartEvent, | |
| 37 | ToDeviceKeyVerificationStartEvent, | |
| 38 | }; | |
| 39 | use matrix_sdk::ruma::events::presence::PresenceEvent; | |
| 40 | use matrix_sdk::ruma::events::reaction::ReactionEventContent; | |
| 41 | use matrix_sdk::ruma::events::receipt::{ReceiptEventContent, ReceiptType}; | |
| 42 | use matrix_sdk::ruma::events::room::encryption::RoomEncryptionEventContent; | |
| 43 | use matrix_sdk::ruma::events::room::member::OriginalSyncRoomMemberEvent; | |
| 44 | use matrix_sdk::ruma::events::room::name::RoomNameEventContent; | |
| 45 | use matrix_sdk::ruma::events::room::redaction::OriginalSyncRoomRedactionEvent; | |
| 46 | use matrix_sdk::ruma::events::sticker::StickerEventContent; | |
| 47 | use matrix_sdk::ruma::events::typing::SyncTypingEvent; | |
| 48 | use matrix_sdk::ruma::events::{ | |
| 49 | AnyMessageLikeEvent, | |
| 50 | AnyMessageLikeEventContent, | |
| 51 | AnyTimelineEvent, | |
| 52 | InitialStateEvent, | |
| 53 | SyncEphemeralRoomEvent, | |
| 54 | SyncMessageLikeEvent, | |
| 55 | SyncStateEvent, | |
| 56 | }; | |
| 57 | use matrix_sdk::ruma::room::RoomType; | |
| 58 | use matrix_sdk::ruma::serde::Raw; | |
| 59 | use matrix_sdk::send_queue::{LocalEcho, LocalEchoContent, RoomSendQueueUpdate, SendQueueUpdate}; | |
| 29 | 60 | use matrix_sdk::{ |
| 30 | Client, | |
| 31 | 61 | ClientBuildError, |
| 32 | 62 | Error as MatrixError, |
| 33 | 63 | RoomDisplayName, |
| 34 | 64 | RoomMemberships, |
| 35 | authentication::matrix::MatrixSession, | |
| 36 | config::{RequestConfig, SyncSettings}, | |
| 37 | encryption::{BackupDownloadStrategy, EncryptionSettings}, | |
| 38 | event_handler::Ctx, | |
| 39 | 65 | reqwest, |
| 40 | room::{Messages, MessagesOptions, Room as MatrixRoom, RoomMember}, | |
| 41 | ruma::{ | |
| 42 | EventId, | |
| 43 | OwnedEventId, | |
| 44 | OwnedRoomId, | |
| 45 | OwnedRoomOrAliasId, | |
| 46 | OwnedUserId, | |
| 47 | RoomId, | |
| 48 | api::client::{ | |
| 49 | filter::{FilterDefinition, LazyLoadOptions, RoomEventFilter, RoomFilter}, | |
| 50 | room::{ | |
| 51 | Visibility, | |
| 52 | create_room::v3::{CreationContent, Request as CreateRoomRequest}, | |
| 53 | }, | |
| 54 | space::get_hierarchy::v1::Request as SpaceHierarchyRequest, | |
| 55 | }, | |
| 56 | assign, | |
| 57 | events::{ | |
| 58 | AnyMessageLikeEvent, | |
| 59 | AnyMessageLikeEventContent, | |
| 60 | AnySyncStateEvent, | |
| 61 | AnyTimelineEvent, | |
| 62 | InitialStateEvent, | |
| 63 | SyncEphemeralRoomEvent, | |
| 64 | SyncMessageLikeEvent, | |
| 65 | SyncStateEvent, | |
| 66 | key::verification::{ | |
| 67 | request::ToDeviceKeyVerificationRequestEvent, | |
| 68 | start::{OriginalSyncKeyVerificationStartEvent, ToDeviceKeyVerificationStartEvent}, | |
| 69 | }, | |
| 70 | presence::PresenceEvent, | |
| 71 | reaction::ReactionEventContent, | |
| 72 | receipt::{ReceiptEventContent, ReceiptThread, ReceiptType}, | |
| 73 | relation::Thread, | |
| 74 | room::{ | |
| 75 | MediaSource, | |
| 76 | encryption::RoomEncryptionEventContent, | |
| 77 | member::OriginalSyncRoomMemberEvent, | |
| 78 | message::{MessageType, Relation, RoomMessageEventContent}, | |
| 79 | name::RoomNameEventContent, | |
| 80 | redaction::OriginalSyncRoomRedactionEvent, | |
| 81 | }, | |
| 82 | sticker::StickerEventContent, | |
| 83 | tag::Tags, | |
| 84 | typing::SyncTypingEvent, | |
| 85 | }, | |
| 86 | room::RoomType, | |
| 87 | serde::Raw, | |
| 88 | }, | |
| 89 | send_queue::{LocalEcho, LocalEchoContent, RoomSendQueueUpdate, SendQueueUpdate}, | |
| 90 | 66 | }; |
| 67 | use matrix_sdk_base::RoomStateFilter; | |
| 68 | use ratatui_image::picker::Picker; | |
| 69 | use tokio::sync::Semaphore; | |
| 70 | use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender, unbounded_channel}; | |
| 71 | use tokio::task::JoinHandle; | |
| 72 | use tracing::{Instrument as _, error, warn}; | |
| 91 | 73 | |
| 92 | use modalkit::errors::UIError; | |
| 93 | use modalkit::prelude::{EditInfo, InfoMessage}; | |
| 94 | ||
| 95 | use crate::base::{EchoLocation, MessageNeed}; | |
| 74 | use crate::base::{CreateRoomFlags, CreateRoomType, EchoLocation, MessageNeed, RoomFetchStatus}; | |
| 96 | 75 | use crate::config::ProxyUrl; |
| 97 | use crate::message::{Message, MessageEvent, MessageId, MessageKey}; | |
| 76 | use crate::message::MessageId; | |
| 98 | 77 | use crate::notifications::register_notifications; |
| 99 | use crate::preview::PreviewKind; | |
| 78 | use crate::prelude::*; | |
| 100 | 79 | use crate::verifications; |
| 101 | use crate::{ | |
| 102 | ApplicationSettings, | |
| 103 | base::{ | |
| 104 | AsyncProgramStore, | |
| 105 | ChatStore, | |
| 106 | CreateRoomFlags, | |
| 107 | CreateRoomType, | |
| 108 | IambError, | |
| 109 | IambResult, | |
| 110 | ProgramStore, | |
| 111 | RoomFetchStatus, | |
| 112 | RoomInfo, | |
| 113 | }, | |
| 114 | }; | |
| 115 | 80 | |
| 116 | 81 | const DEFAULT_ENCRYPTION_SETTINGS: EncryptionSettings = EncryptionSettings { |
| 117 | 82 | auto_enable_cross_signing: true, |
| @@ -265,7 +230,8 @@ async fn load_older_one( | ||
| 265 | 230 | }; |
| 266 | 231 | opts.limit = limit.into(); |
| 267 | 232 | |
| 268 | let Messages { end, chunk, .. } = room.messages(opts).await.map_err(IambError::from)?; | |
| 233 | let MatrixMessages { end, chunk, .. } = | |
| 234 | room.messages(opts).await.map_err(IambError::from)?; | |
| 269 | 235 | |
| 270 | 236 | let mut msgs = vec![]; |
| 271 | 237 | |