Git Product home page Git Product logo

vi-rs's Introduction

VI

Cargo Crate Docs License

A input method library for Vietnamese input engine written completely in Rust

What is this?

Since typing Vietnamese on Linux is pretty painful at the momment, a better input engine is always needed. To accommodate the future engines that will be built in Rust, this library existed to transform key inputs into the Vietnamese string output.

If you wish to find out how it works, I have written a short blog post (in Vietnamese) on how the library place a tone mark when it received the user input. Read it here.

Installation

Add vi to your dependencies in Cargo.toml.

[dependencies]
vi = "0.7.0"

Examples

With vi, you can start building your own Vietnamese IME without worrying about how Vietnamese tone mark placement works. All you have to do is to implement a keyboard listener & a key sending system.

extern crate vi;

use vi::vni;

fn main() {
    let inputs = vec![
        vec!['v', 'i', 'e', 't', '6', '5'],
        vec!['n', 'a', 'm']
    ];

    let mut result = String::new();
    for input in inputs {
        vni::transform_buffer(input.iter().cloned(), &mut result);
        result.push(' ');
    }
    
    println!("{}", result); // prints "việt nam "
}

Please refer to the examples/ directory to learn more.

Support

  • VNI
  • Telex

Project status

Currently, this project is still at its early stage of development. There might be some minor bugs but overall, it should be 95% functional.

Creator

Want to support me? Consider buying me a coffee:)

ko-fi

vi-rs's People

Contributors

huytd avatar quangio avatar tesuji avatar unrealhoang avatar zerox-dg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

vi-rs's Issues

[bug] telex: www stucks as w

cc #30
version: b627959

Given this code:

let mut out = String::new();
vi::telex::transform_buffer("wwwww".chars(), &mut out);
assert_eq!("wwww", out);

The assertion fails.

"www" is frequently typed as in "www.google.com".

Caching word information after each transformation

Instead of re-parsing the same word over and over, we can store the word & its transformations in memory. For example:

struct Word {
  initial_consonant: String,
  vowel: String,
  final_consonant: String,
  tone_mark: ToneMark
}

bug: telex: consecutive d's stucks at đd

Reproduce

fn main() {
    let mut result = String::new();
    for n in 1..10 {
        let mut input = Vec::new();
        for _ in 0..n {
            input.push('d');
        }
        vi::telex::transform_buffer(input.iter().cloned(), &mut result);
        result.push('\n');
    }
    println!("{}", result);
}
  • Expect (similar to consecutive a's)
d
đ
dd
ddd
dddd
...
  • Actual
d
đ
dd
đd
đd
đd
đd
đd
đd

Cause

  • modify_letter always add tone to the first d/đ --> stuck
  • if i modified so that modify_letter add tone to the last d, then reposition_letter_modification will always reorder the modifications and put the tone back to the first d/đ --> stuck
  • Finally is_valid_word does not recognize dd as an invalid word (like aa). Might be best to fix here.

Split up processor to more separated functions

This is so that we can introduce easier definition of a typing method. Currently telex method is pretty complicated & debugging is quite difficult.

We might want to introduce new methods derived from the telex method too, so having a simple interface to define typing methods is pretty important.

Need a different restore rule for `ư` incase of `uw` and `w`

Currently, when typing w after ư, we always restore it as uw.

This is true when the user first typed uw to make a ư and want to hit w again to dismiss that.

But in case the user typed w to make a ư, the next w should be restored as w not uw.

Panic in transform_buffer

After v0.3.7, we got a few panic cases, for example, when the user typing "land" in Telex mode:

thread '<unnamed>' panicked at 'Couldn't retrieve replace char for l for Dyet', vi-rs-5b567bc8b512911b/83317ad/src/processor.rs:185:36
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Ideally transform_buffer should not be panicked, but in case it is, we probably want to make it a function returning a Result, so the caller side can handle it.

huytd/goxkey#42

design question: Should `transform_buffer` be incremental?

Hi, I use vi-rs for my linux input engine with a IBUS framework.
But IBus passes a single char each time a key typed.
For every key typed, I should display the preview string (as in Vietnameses) to users.
So I couldn't cache each/a word (Vec<char>) and pass it to transform_buffer.
So transform_buffer is called for every key typed.

So I wonder if we could create a new incremental transform_buffer.

fn transform_buffer_incremental<'def, 'buf>(
    def: &'def Definition,
    output: &'buf mut String,
) -> IncrementalBuffer;

struct IncrementalBuffer<'def, 'buf> {
    def: &'def Definition,
    output: &'buf mut String,
    input: Vec<char>,
    // cache something for example a Word.
}

impl IncrementalBuffer {
    pub fn push(&mut self, ch: char) -> TransformResult {
        self.input.push(ch);
        // ...
    }
    pub fn view(&self) -> &str;
    pub fn clear(&mut self) {
        self.output.clear();
        // clear cache
    }
}

Replace tone mark for the case of "uâ"

Currently, the replace tone mark logic works fine with "ua", for example "múa", "xúa"

But when the letter after "u" is a modified "a" like "â" "ă", the tone mark should be put on that, for example: "xúât hiện"

Note that this works fine in telex mode if I type: x u a a t s - xuất
But if I type: x u a a s t - it becomes xúât

`transform_buffer` crashes when received unexpected input

This code crashes unexpectedly:

    let mut out = String::new();
    let inp = "sdd";
    telex::transform_buffer(inp.chars(), &mut out);

I agree the input string is not valid.
Could transform_buffer returns an explicit error to handle this case?
So that my process -- run as daemon -- doesn't exit early.

Thank advance for your considerations.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.