Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feat/clap-derive
Browse files Browse the repository at this point in the history
  • Loading branch information
LoricAndre committed Nov 18, 2024
2 parents 407b6e6 + c932a1f commit baf9d55
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 50 deletions.
44 changes: 22 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,16 @@ The skim project contains several components:

## Package Managers

| Distribution | Package Manager | Command |
| -------------- | ----------------- | ---------------------------- |
| macOS | Homebrew | `brew install sk` |
| macOS | MacPorts | `sudo port install skim` |
| Fedora | dnf | `dnf install skim` |
| Alpine | apk | `apk add skim` |
| Arch | pacman | `pacman -S skim` |
| Distribution | Package Manager | Command |
| -------------- | ----------------- | ------------------------- |
| macOS | Homebrew | `brew install sk` |
| macOS | MacPorts | `sudo port install skim` |
| Fedora | dnf | `dnf install skim` |
| Alpine | apk | `apk add skim` |
| Arch | pacman | `pacman -S skim` |
| Gentoo | Portage | `emerge --ask app-misc/skim` |
| Guix | guix | `guix install skim` |
| Void | XBPS | `xbps-install -S skim` |

See [repology](https://repology.org/project/skim/versions) for a comprehensive overview of package availability.

Expand Down
8 changes: 7 additions & 1 deletion plugin/skim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,12 @@ function! skim#wrap(...)
endif
endif

" Interactive commands should use --cmd-history for query history
let history_option = '--history'
if index(opts['options'], '-i') != -1
let history_option = '--cmd-history'
endif

" Colors: g:skim_colors
let opts.options = s:defaults() .' '. s:evaluate_opts(get(opts, 'options', ''))

Expand All @@ -352,7 +358,7 @@ function! skim#wrap(...)
call mkdir(dir, 'p')
endif
let history = skim#shellescape(dir.'/'.name)
let opts.options = join(['--history', history, opts.options])
let opts.options = join([history_option, history, opts.options])
endif

" Action: g:skim_action
Expand Down
19 changes: 17 additions & 2 deletions shell/key-bindings.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,23 @@ bindkey '\ec' skim-cd-widget
skim-history-widget() {
local selected num
setopt localoptions noglobsubst noposixbuiltins pipefail no_aliases 2> /dev/null
selected=( $(fc -rl 1 | perl -ne 'print if !$seen{(/^\s*[0-9]+\**\s+(.*)/, $1)}++' |
SKIM_DEFAULT_OPTIONS="--height ${SKIM_TMUX_HEIGHT:-40%} $SKIM_DEFAULT_OPTIONS -n2..,.. --tiebreak=index --bind=ctrl-r:toggle-sort $SKIM_CTRL_R_OPTS --query=${(qqq)LBUFFER} --no-multi" $(__skimcmd)) )
local awk_filter='{ cmd=$0; sub(/^\s*[0-9]+\**\s+/, "", cmd); if (!seen[cmd]++) print $0 }' # filter out duplicates
local n=2 fc_opts=''
if [[ -o extended_history ]]; then
local today=$(date +%Y-%m-%d)
# For today's commands, replace date ($2) with "today", otherwise remove time ($3).
# And filter out duplicates.
awk_filter='{
if ($2 == "'$today'") sub($2 " ", "today'\''")
else sub($3, "")
line=$0; $1=""; $2=""; $3=""
if (!seen[$0]++) print line
}'
fc_opts='-i'
n=3
fi
selected=( $(fc -rl $fc_opts 1 | awk "$awk_filter" |
SKIM_DEFAULT_OPTIONS="--height ${SKIM_TMUX_HEIGHT:-40%} $SKIM_DEFAULT_OPTIONS -n$n..,.. --tiebreak=index --bind=ctrl-r:toggle-sort $SKIM_CTRL_R_OPTS --query=${(qqq)LBUFFER} --no-multi" $(__skimcmd)) )
local ret=$?
if [ -n "$selected" ]; then
num=$selected[1]
Expand Down
57 changes: 56 additions & 1 deletion skim/src/ansi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl Perform for ANSIParser {
match code[0] {
0 => attr = Attr::default(),
1 => attr.effect |= Effect::BOLD,
2 => attr.effect |= !Effect::BOLD,
2 => attr.effect |= Effect::DIM,
4 => attr.effect |= Effect::UNDERLINE,
5 => attr.effect |= Effect::BLINK,
7 => attr.effect |= Effect::REVERSE,
Expand Down Expand Up @@ -324,6 +324,24 @@ impl<'a> From<(&'a str, &'a [usize], Attr)> for AnsiString<'a> {
}
}

impl<'a> std::ops::Add for AnsiString<'a> {
type Output = AnsiString<'a>;

fn add(mut self, rhs: Self) -> Self::Output {
let len = self.stripped.as_ref().len() as u32;
if let Some(fragments) = rhs.fragments {
if self.fragments.is_none() {
self.fragments = Some(vec![]);
}
for (attr, (start, end)) in fragments.iter() {
self.fragments.as_mut().unwrap().push((*attr, (start + len, end + len)));
}
}
self.stripped = Cow::owned(self.stripped.into_owned() + rhs.stripped.as_ref());
self
}
}

/// An iterator over all the (char, attr) characters.
pub struct AnsiStringIterator<'a> {
fragments: &'a [(Attr, (u32, u32))],
Expand Down Expand Up @@ -595,6 +613,26 @@ mod tests {
);
}

#[test]
fn test_ansi_string_add() {
let default_attr = Attr::default();
let ar = Attr::default().bg(Color::RED);
let ab = Attr::default().bg(Color::BLUE);

let string_a = AnsiString::new_str("foo", vec![(ar, (1, 3))]);
let string_b = AnsiString::new_str("bar", vec![(ab, (0, 2))]);
let string_c = string_a + string_b;

let mut it = string_c.iter();
assert_eq!(Some(('f', default_attr)), it.next());
assert_eq!(Some(('o', ar)), it.next());
assert_eq!(Some(('o', ar)), it.next());
assert_eq!(Some(('b', ab)), it.next());
assert_eq!(Some(('a', ab)), it.next());
assert_eq!(Some(('r', default_attr)), it.next());
assert_eq!(None, it.next());
}

#[test]
fn test_multi_byte_359() {
// https://github.com/lotabout/skim/issues/359
Expand All @@ -606,4 +644,21 @@ mod tests {
assert_eq!(Some(('a', highlight)), it.next());
assert_eq!(None, it.next());
}

#[test]
fn test_ansi_dim() {
// https://github.com/lotabout/skim/issues/495
let input = "\x1B[2mhi\x1b[0m";
let ansistring = ANSIParser::default().parse_ansi(input);
let mut it = ansistring.iter();
let attr = Attr {
effect: Effect::DIM,
..Attr::default()
};

assert_eq!(Some(('h', attr)), it.next());
assert_eq!(Some(('i', attr)), it.next());
assert_eq!(None, it.next());
assert_eq!(ansistring.stripped(), "hi");
}
}
2 changes: 1 addition & 1 deletion skim/src/engine/fuzzy.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::cmp::min;
use std::fmt::{Display, Error, Formatter};
use std::sync::Arc;

Expand All @@ -9,7 +10,6 @@ use fuzzy_matcher::FuzzyMatcher;
use crate::item::RankBuilder;
use crate::{CaseMatching, MatchEngine};
use crate::{MatchRange, MatchResult, SkimItem};
use bitflags::_core::cmp::min;

//------------------------------------------------------------------------------
#[derive(ValueEnum, Debug, Copy, Clone, Default)]
Expand Down
11 changes: 4 additions & 7 deletions skim/src/event.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// All the events that will be used

use bitflags::bitflags;
use std::sync::mpsc::{Receiver, Sender};
use tuikit::key::Key;

Expand Down Expand Up @@ -77,12 +76,10 @@ pub enum Event {
__Nonexhaustive,
}

bitflags! {
/// `Effect` is the effect of a text
pub struct UpdateScreen: u8 {
const REDRAW = 0b0000_0001;
const DONT_REDRAW = 0b0000_0010;
}
/// `Effect` is the effect of a text
pub enum UpdateScreen {
Redraw,
DontRedraw,
}

pub trait EventHandler {
Expand Down
2 changes: 1 addition & 1 deletion skim/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,6 @@ impl Widget<Event> for Header {

impl EventHandler for Header {
fn handle(&mut self, _event: &Event) -> UpdateScreen {
UpdateScreen::DONT_REDRAW
UpdateScreen::DontRedraw
}
}
4 changes: 2 additions & 2 deletions skim/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ fn get_default_key_map() -> HashMap<Key, ActionChain> {
ret.insert(Key::CtrlRight, vec![Event::EvActForwardWord]);
ret.insert(Key::ShiftRight, vec![Event::EvActForwardWord]);
ret.insert(Key::Alt('d'), vec![Event::EvActKillWord]);
ret.insert(Key::ShiftUp, vec![Event::EvActPreviewPageUp(1)]);
ret.insert(Key::ShiftDown, vec![Event::EvActPreviewPageDown(1)]);
ret.insert(Key::ShiftUp, vec![Event::EvActPreviewUp(1)]);
ret.insert(Key::ShiftDown, vec![Event::EvActPreviewDown(1)]);
ret.insert(Key::PageDown, vec![Event::EvActPageDown(1)]);
ret.insert(Key::PageUp, vec![Event::EvActPageUp(1)]);
ret.insert(Key::Ctrl('r'), vec![Event::EvActRotateMode]);
Expand Down
4 changes: 2 additions & 2 deletions skim/src/previewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,9 @@ impl EventHandler for Previewer {
EvActPreviewRight(diff) => self.act_scroll_right(*diff),
EvActPreviewPageUp(diff) => self.act_scroll_down(-(height as i32 * *diff)),
EvActPreviewPageDown(diff) => self.act_scroll_down(height as i32 * *diff),
_ => return UpdateScreen::DONT_REDRAW,
_ => return UpdateScreen::DontRedraw,
}
UpdateScreen::REDRAW
UpdateScreen::Redraw
}
}

Expand Down
4 changes: 2 additions & 2 deletions skim/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,9 +534,9 @@ impl EventHandler for Query {
}

if self.query_changed(mode, query_before_len, query_after_len, cmd_before_len, cmd_after_len) {
UpdateScreen::REDRAW
UpdateScreen::Redraw
} else {
UpdateScreen::DONT_REDRAW
UpdateScreen::DontRedraw
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions skim/src/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,9 @@ impl EventHandler for Selection {
EvActScrollRight(diff) => {
self.act_scroll(*diff);
}
_ => return UpdateScreen::DONT_REDRAW,
_ => return UpdateScreen::DontRedraw,
}
UpdateScreen::REDRAW
UpdateScreen::Redraw
}
}

Expand Down

0 comments on commit baf9d55

Please sign in to comment.