Skip to content

Commit 383d0eb

Browse files
committed
close #49, compile on stable
Previouly, skim relys on nightly rust for `io::chars` Now use crate utf8parse instead. Check rust-lang/rust#27802 (comment)
1 parent 4f8e6ea commit 383d0eb

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ regex = "0.2"
1313
lazy_static = "0.2.1"
1414
clippy = {version = "*", optional = true}
1515
shlex = "0.1.1"
16+
utf8parse = "0.1.0"
1617

1718
[dependencies.ncurses]
1819
version = "*"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Plug 'lotabout/skim', { 'dir': '~/.skim', 'do': './install' }
6363

6464
## Build Manually
6565

66-
Current requires nightly rust to build. Clone the repo and run:
66+
Clone the repo and run:
6767

6868
```
6969
cargo build --release

src/input.rs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::fs::File;
88
use std::collections::HashMap;
99
use std::collections::VecDeque;
1010
use std::time::Duration;
11+
use utf8parse;
1112

1213
use event::{Event, EventArg, parse_action};
1314

@@ -93,6 +94,30 @@ impl Input {
9394
}
9495
}
9596

97+
// check https://github.com/rust-lang/rust/issues/27802#issuecomment-270555935
98+
struct SimpleUtf8Receiver {
99+
tx: Sender<char>,
100+
}
101+
102+
impl SimpleUtf8Receiver {
103+
pub fn new(tx: Sender<char>) -> Self {
104+
SimpleUtf8Receiver {
105+
tx: tx,
106+
}
107+
}
108+
}
109+
110+
impl utf8parse::Receiver for SimpleUtf8Receiver {
111+
fn codepoint(&mut self, ch: char) {
112+
self.tx.send(ch);
113+
}
114+
115+
fn invalid_sequence(&mut self) {
116+
// ignore it
117+
}
118+
}
119+
120+
96121
struct KeyBoard {
97122
rx: Receiver<char>,
98123
buf: VecDeque<char>,
@@ -102,10 +127,10 @@ impl KeyBoard {
102127
pub fn new(f: File) -> Self {
103128
let (tx, rx) = channel();
104129
thread::spawn(move || {
105-
for ch in f.chars() {
106-
if ch.is_ok() {
107-
let _ = tx.send(ch.unwrap());
108-
}
130+
let mut utf8_receiver = SimpleUtf8Receiver::new(tx);
131+
let mut utf8_parser = utf8parse::Parser::new();
132+
for byte in f.bytes() {
133+
utf8_parser.advance(&mut utf8_receiver, byte.unwrap());
109134
}
110135
});
111136

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
#![feature(io)]
21
#![cfg_attr(feature="clippy", feature(plugin))]
32
#![cfg_attr(feature="clippy", plugin(clippy))]
43
extern crate libc;
54
extern crate ncurses;
65
extern crate getopts;
76
extern crate regex;
87
extern crate shlex;
8+
extern crate utf8parse;
99
#[macro_use] extern crate lazy_static;
1010
mod item;
1111
mod reader;

0 commit comments

Comments
 (0)