Skip to content

Commit

Permalink
close #49, compile on stable
Browse files Browse the repository at this point in the history
Previouly, skim relys on nightly rust for `io::chars`
Now use crate utf8parse instead.
Check rust-lang/rust#27802 (comment)
  • Loading branch information
lotabout committed Jan 19, 2017
1 parent 4f8e6ea commit 383d0eb
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ regex = "0.2"
lazy_static = "0.2.1"
clippy = {version = "*", optional = true}
shlex = "0.1.1"
utf8parse = "0.1.0"

[dependencies.ncurses]
version = "*"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Plug 'lotabout/skim', { 'dir': '~/.skim', 'do': './install' }

## Build Manually

Current requires nightly rust to build. Clone the repo and run:
Clone the repo and run:

```
cargo build --release
Expand Down
33 changes: 29 additions & 4 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::fs::File;
use std::collections::HashMap;
use std::collections::VecDeque;
use std::time::Duration;
use utf8parse;

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

Expand Down Expand Up @@ -93,6 +94,30 @@ impl Input {
}
}

// check https://github.com/rust-lang/rust/issues/27802#issuecomment-270555935
struct SimpleUtf8Receiver {
tx: Sender<char>,
}

impl SimpleUtf8Receiver {
pub fn new(tx: Sender<char>) -> Self {
SimpleUtf8Receiver {
tx: tx,
}
}
}

impl utf8parse::Receiver for SimpleUtf8Receiver {
fn codepoint(&mut self, ch: char) {
self.tx.send(ch);
}

fn invalid_sequence(&mut self) {
// ignore it
}
}


struct KeyBoard {
rx: Receiver<char>,
buf: VecDeque<char>,
Expand All @@ -102,10 +127,10 @@ impl KeyBoard {
pub fn new(f: File) -> Self {
let (tx, rx) = channel();
thread::spawn(move || {
for ch in f.chars() {
if ch.is_ok() {
let _ = tx.send(ch.unwrap());
}
let mut utf8_receiver = SimpleUtf8Receiver::new(tx);
let mut utf8_parser = utf8parse::Parser::new();
for byte in f.bytes() {
utf8_parser.advance(&mut utf8_receiver, byte.unwrap());
}
});

Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#![feature(io)]
#![cfg_attr(feature="clippy", feature(plugin))]
#![cfg_attr(feature="clippy", plugin(clippy))]
extern crate libc;
extern crate ncurses;
extern crate getopts;
extern crate regex;
extern crate shlex;
extern crate utf8parse;
#[macro_use] extern crate lazy_static;
mod item;
mod reader;
Expand Down

0 comments on commit 383d0eb

Please sign in to comment.