Code Monkey home page Code Monkey logo

go-rearrange's Introduction

go-rearrange

Build Status MIT License

Overview

This is a Golang library to interactively rearrange a text data on a terminal.

Description

When a text data is rearranged, there are many applications for automatically sorting text data. But there are a little CLI applications for manually rearranging it using. Furthermore, I just had to create an application for manually and interactively rearranging data. So I created this.

Features

  • Data can be interactively rearranged on your terminal as a CLI tool.
  • Output rearranged data as []string.
  • Retrieve selected values and select history.

Install

You can install this using go get as follows.

$ go get -u github.com/tanaikech/go-rearrange

This library uses termbox-go.

Usage

result, history, err := rearrange.Do(data, step, selectmode, indexmode)

Input

  • data ([]string) : Data for rearranging. This has to be 1 dimensional string array. Each element is rearranged.
  • step (int) : Number of steps for PageUp, PageDown.
  • selectmode (bool) : If this is true, it's used as select mode. In this case, users only select a value. The selected values are output.
  • indexmode (bool) : If this is true, the rearranged result is output as the change of index for the source data. For example, if the source data and rearranged data are ["a", "b", "c"] and ["c", "b", "a"], respectively. The output will become [2, 1, 0].

Output

  • result ([]string) : Rearranged data. Data is returned as []string.
  • history ([]string) : History of rearranged data. When the data is rearranged, the selected data is saved as a history like [{Index:9 Value:sample10} {Index:1 Value:sample1}].
  • err (error) : Error.

Keys for rearranging

Use up, down, page up, page down, home, end, enter, back space, Ctrl + c and escape keys.

Key Effect
Up, Down Moving one line
Page up, Page down Moving several lines
Home, End Moving top and bottom of data
Enter Selecting a value to rearrange
Back space or Space Reset the rearranged data
Ctrl + c or Escape Finishing rearranging

Applications

  • gorearrange : This is a CLI tool to interactively rearrange a text data on a terminal.
  • ggsrun : This was used for rearranging scripts in a GAS project.

Update History

  • v1.0.0 (October 15, 2017)

    Initial release.

  • v1.0.1 (October 16, 2017)

    • As one of outputs, indexmode (bool) was added. If this is true, the rearranged result is output as the change of index for the source data. For example, if the source data and rearranged data are ["a", "b", "c"] and ["c", "b", "a"], respectively. The output will become [2, 1, 0].
  • v1.0.2 (October 18, 2017)

    • From this version, data included multi-bytes characters can be used. At Linux, it works fine. At Windows DOS, rearranging and selecting data can be done. But the displayed data is shifted. Although this may be a bug of termbox-go, I don't know the reason. I'm sorry. On the other hand, data with only single-byte characters works fine. About MAC, I don't have it. If someone can confirm and tell me it, I'm glad.

TOP

go-rearrange's People

Contributors

tanaikech avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

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.