tty-cursor-0.7.1/0000755000175000017500000000000013620101243013502 5ustar gabstergabstertty-cursor-0.7.1/tty-cursor.gemspec0000644000175000017500000000451613620101243017210 0ustar gabstergabster######################################################### # This file has been automatically generated by gem2tgz # ######################################################### # -*- encoding: utf-8 -*- # stub: tty-cursor 0.7.1 ruby lib Gem::Specification.new do |s| s.name = "tty-cursor".freeze s.version = "0.7.1" s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version= s.metadata = { "allowed_push_host" => "https://rubygems.org", "bug_tracker_uri" => "https://github.com/piotrmurach/tty-cursor/issues", "changelog_uri" => "https://github.com/piotrmurach/tty-cursor/blob/master/CHANGELOG.md", "documentation_uri" => "https://www.rubydoc.info/gems/tty-cursor", "homepage_uri" => "https://ttytoolkit.org", "source_code_uri" => "https://github.com/piotrmurach/tty-cursor" } if s.respond_to? :metadata= s.require_paths = ["lib".freeze] s.authors = ["Piotr Murach".freeze] s.bindir = "exe".freeze s.date = "2020-01-25" s.description = "The purpose of this library is to help move the terminal cursor around and manipulate text by using intuitive method calls.".freeze s.email = ["piotr@piotrmurach.com".freeze] s.extra_rdoc_files = ["CHANGELOG.md".freeze, "README.md".freeze] s.files = ["CHANGELOG.md".freeze, "LICENSE.txt".freeze, "README.md".freeze, "lib/tty-cursor.rb".freeze, "lib/tty/cursor.rb".freeze, "lib/tty/cursor/version.rb".freeze] s.homepage = "https://ttytoolkit.org".freeze s.licenses = ["MIT".freeze] s.required_ruby_version = Gem::Requirement.new(">= 2.0.0".freeze) s.rubygems_version = "2.7.6.2".freeze s.summary = "Terminal cursor positioning, visibility and text manipulation.".freeze if s.respond_to? :specification_version then s.specification_version = 4 if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then s.add_development_dependency(%q.freeze, [">= 1.6"]) s.add_development_dependency(%q.freeze, [">= 0"]) s.add_development_dependency(%q.freeze, ["~> 3.1"]) else s.add_dependency(%q.freeze, [">= 1.6"]) s.add_dependency(%q.freeze, [">= 0"]) s.add_dependency(%q.freeze, ["~> 3.1"]) end else s.add_dependency(%q.freeze, [">= 1.6"]) s.add_dependency(%q.freeze, [">= 0"]) s.add_dependency(%q.freeze, ["~> 3.1"]) end end tty-cursor-0.7.1/lib/0000755000175000017500000000000013620101243014250 5ustar gabstergabstertty-cursor-0.7.1/lib/tty/0000755000175000017500000000000013620101243015070 5ustar gabstergabstertty-cursor-0.7.1/lib/tty/cursor/0000755000175000017500000000000013620101243016405 5ustar gabstergabstertty-cursor-0.7.1/lib/tty/cursor/version.rb0000644000175000017500000000015113620101243020414 0ustar gabstergabster# frozen_string_literal: true module TTY module Cursor VERSION = "0.7.1" end # Cursor end # TTY tty-cursor-0.7.1/lib/tty/cursor.rb0000644000175000017500000001051513620101243016734 0ustar gabstergabster# frozen_string_literal: true require_relative 'cursor/version' module TTY # Terminal cursor movement ANSI codes module Cursor module_function ESC = "\e".freeze CSI = "\e[".freeze DEC_RST = 'l'.freeze DEC_SET = 'h'.freeze DEC_TCEM = '?25'.freeze # Make cursor visible # @api public def show CSI + DEC_TCEM + DEC_SET end # Hide cursor # @api public def hide CSI + DEC_TCEM + DEC_RST end # Switch off cursor for the block # @api public def invisible(stream = $stdout) stream.print(hide) yield ensure stream.print(show) end # Save current position # @api public def save Gem.win_platform? ? CSI + 's' : ESC + '7' end # Restore cursor position # @api public def restore Gem.win_platform? ? CSI + 'u' : ESC + '8' end # Query cursor current position # @api public def current CSI + '6n' end # Set the cursor absolute position # @param [Integer] row # @param [Integer] column # @api public def move_to(row = nil, column = nil) return CSI + 'H' if row.nil? && column.nil? CSI + "#{column + 1};#{row + 1}H" end # Move cursor relative to its current position # # @param [Integer] x # @param [Integer] y # # @api public def move(x, y) (x < 0 ? backward(-x) : (x > 0 ? forward(x) : '')) + (y < 0 ? down(-y) : (y > 0 ? up(y) : '')) end # Move cursor up by n # @param [Integer] n # @api public def up(n = nil) CSI + "#{(n || 1)}A" end alias cursor_up up # Move the cursor down by n # @param [Integer] n # @api public def down(n = nil) CSI + "#{(n || 1)}B" end alias cursor_down down # Move the cursor backward by n # @param [Integer] n # @api public def backward(n = nil) CSI + "#{n || 1}D" end alias cursor_backward backward # Move the cursor forward by n # @param [Integer] n # @api public def forward(n = nil) CSI + "#{n || 1}C" end alias cursor_forward forward # Cursor moves to nth position horizontally in the current line # @param [Integer] n # the nth aboslute position in line # @api public def column(n = nil) CSI + "#{n || 1}G" end # Cursor moves to the nth position vertically in the current column # @param [Integer] n # the nth absolute position in column # @api public def row(n = nil) CSI + "#{n || 1}d" end # Move cursor down to beginning of next line # @api public def next_line CSI + 'E' + column(1) end # Move cursor up to beginning of previous line # @api public def prev_line CSI + 'A' + column(1) end # Erase n characters from the current cursor position # @api public def clear_char(n = nil) CSI + "#{n}X" end # Erase the entire current line and return to beginning of the line # @api public def clear_line CSI + '2K' + column(1) end # Erase from the beginning of the line up to and including # the current cursor position. # @api public def clear_line_before CSI + '1K' end # Erase from the current position (inclusive) to # the end of the line # @api public def clear_line_after CSI + '0K' end # Clear a number of lines # # @param [Integer] n # the number of lines to clear # @param [Symbol] :direction # the direction to clear, default :up # # @api public def clear_lines(n, direction = :up) n.times.reduce([]) do |acc, i| dir = direction == :up ? up : down acc << clear_line + ((i == n - 1) ? '' : dir) end.join end alias clear_rows clear_lines # Clear screen down from current position # @api public def clear_screen_down CSI + 'J' end # Clear screen up from current position # @api public def clear_screen_up CSI + '1J' end # Clear the screen with the background colour and moves the cursor to home # @api public def clear_screen CSI + '2J' end # Scroll display up one line # @api public def scroll_up ESC + 'M' end # Scroll display down one line # @api public def scroll_down ESC + 'D' end end # Cursor end # TTY tty-cursor-0.7.1/lib/tty-cursor.rb0000644000175000017500000000003613620101243016727 0ustar gabstergabsterrequire_relative 'tty/cursor' tty-cursor-0.7.1/README.md0000644000175000017500000001627413620101243014773 0ustar gabstergabster
tty logo
# TTY::Cursor [![Gitter](https://badges.gitter.im/Join%20Chat.svg)][gitter] [![Gem Version](https://badge.fury.io/rb/tty-cursor.svg)][gem] [![Build Status](https://secure.travis-ci.org/piotrmurach/tty-cursor.svg?branch=master)][travis] [![Build status](https://ci.appveyor.com/api/projects/status/4k7cd69jscwg7fl7?svg=true)][appveyor] [![Code Climate](https://codeclimate.com/github/piotrmurach/tty-cursor/badges/gpa.svg)][codeclimate] [![Coverage Status](https://coveralls.io/repos/piotrmurach/tty-cursor/badge.svg)][coverage] [![Inline docs](http://inch-ci.org/github/piotrmurach/tty-cursor.svg?branch=master)][inchpages] [gitter]: https://gitter.im/piotrmurach/tty [gem]: http://badge.fury.io/rb/tty-cursor [travis]: http://travis-ci.org/piotrmurach/tty-cursor [appveyor]: https://ci.appveyor.com/project/piotrmurach/tty-cursor [codeclimate]: https://codeclimate.com/github/piotrmurach/tty-cursor [coverage]: https://coveralls.io/r/piotrmurach/tty-cursor [inchpages]: http://inch-ci.org/github/piotrmurach/tty-cursor > Terminal cursor positioning, visibility and text manipulation. The purpose of this library is to help move the terminal cursor around and manipulate text by using intuitive method calls. **TTY::Cursor** provides independent cursor movement component for [TTY](https://github.com/piotrmurach/tty) toolkit. ## Installation Add this line to your application's Gemfile: ```ruby gem 'tty-cursor' ``` And then execute: $ bundle Or install it yourself as: $ gem install tty-cursor ## Contents * [1. Usage](#1-usage) * [2. Interface](#2-interface) * [2.1 Cursor Positioning](#21-cursor-positioning) * [2.1.1 move_to(x, y)](#211-move_tox-y) * [2.1.2 move(x, y)](#212-movex-y) * [2.1.3 up(n)](#213-upn) * [2.1.4 down(n)](#214-downn) * [2.1.5 forward(n)](#215-forwardn) * [2.1.6 backward(n)](#216-backwardn) * [2.1.7 column(n)](#217-columnn) * [2.1.8 row(n)](#218-rown) * [2.1.9 next_line](#219-next_line) * [2.1.10 prev_line](#2110-prev_line) * [2.1.11 save](#2111-save) * [2.1.12 restore](#2112-restore) * [2.1.13 current](#2113-current) * [2.2 Cursor Visibility](#22-cursor-visibility) * [2.2.1 show](#221-show) * [2.2.2 hide](#222-hide) * [2.2.3 invisible(stream)](#223-invisiblestream) * [2.3 Text Clearing](#23-text-clearing) * [2.3.1 clear_char(n)](#231-clear_charn) * [2.3.2 clear_line](#232-clear_line) * [2.3.3 clear_line_before](#233-clear_line_before) * [2.3.4 clear_line_after](#234-clear_line_after) * [2.3.5 clear_lines(n, direction)](#235-clear_linesn-direction) * [2.3.6 clear_screen_down](#236-clear_screen_down) * [2.3.7 clear_screen_up](#237-clear_screen_up) * [2.3.8 clear_screen](#238-clear_screen) * [2.4 Scrolling](#24-scrolling) * [2.4.1 scroll_down](#241-scroll_down) * [2.4.2 scroll_up](#242-scroll_up) ## 1. Usage **TTY::Cursor** is just a module hence you can reference it for later like so: ```ruby cursor = TTY::Cursor ``` and to move the cursor current position by 5 rows up and 2 columns right do: ```ruby print cursor.up(5) + cursor.forward(2) ``` or call `move` to move cursor relative to current position: ```ruby print cursor.move(5, 2) ``` to remove text from the current line do: ```ruby print cursor.clear_line ``` ## 2. Interface ### 2.1 Cursor Positioning All methods in this section allow to position the cursor around the terminal viewport. Cursor movement will be bounded by the current viewport into the buffer. Scrolling (if available) will not occur. #### 2.1.1 move_to(x, y) Set the cursor absolute position to `x` and `y` coordinate, where `x` is the column of the `y` line. If no row/column parameters are provided, the cursor will move to the home position, at the upper left of the screen: ```ruby cursor.move_to ``` #### 2.1.2 move(x, y) Move cursor by x columns and y rows relative to its current position. #### 2.1.3 up(n) Move the cursor up by `n` rows; the default n is `1`. #### 2.1.4 down(n) Move the cursor down by `n` rows; the default n is `1`. #### 2.1.5 forward(n) Move the cursor forward by `n` columns; the default n is `1`. #### 2.1.6 backward(n) Move the cursor backward by `n` columns; the default n is `1`. #### 2.1.7 column(n) Cursor moves to ``th position horizontally in the current line. #### 2.1.8 row(n) Cursor moves to the ``th position vertically in the current column. #### 2.1.9 next_line Move the cursor down to the beginning of the next line. #### 2.1.10 prev_line Move the cursor up to the beginning of the previous line. #### 2.1.11 save Save current cursor position. #### 2.1.12 restore Restore cursor position after a save cursor was called. #### 2.1.13 current Query current cursor position ### 2.2 Cursor Visibility The following methods control the visibility of the cursor. #### 2.2.1 show Show the cursor. #### 2.2.2 hide Hide the cursor. #### 2.2.3 invisible(stream) To hide the cursor for the duration of the block do: ```ruby cursor.invisible { ... } ``` By default standard output will be used but you can change that by passing a different stream that responds to `print` call: ```ruby cursor.invisible($stderr) { .... } ``` ### 2.3 Text Clearing All methods in this section provide APIs to modify text buffer contents. #### 2.3.1 clear_char(n) Erase `` characters from the current cursor position by overwriting them with space character. #### 2.3.2 clear_line Erase the entire current line and return cursor to beginning of the line. #### 2.3.3 clear_line_before Erase from the beginning of the line up to and including the current position. #### 2.3.4 clear_line_after Erase from the current position (inclusive) to the end of the line/display. #### 2.3.5 clear_lines(n, direction) Erase `n` rows in given direction; the default direction is `:up`. ```ruby cursor.clear_lines(5, :down) ``` #### 2.3.6 clear_screen Erase the screen with the background colour and moves the cursor to home. #### 2.3.7 clear_screen_down Erase the screen from the current line down to the bottom of the screen. #### 2.3.8 clear_screen_up Erase the screen from the current line up to the top of the screen. ### 2.4 Scrolling #### 2.4.1 scroll_down Scroll display down one line. ### 2.4.2 scroll_up Scroll display up one line. ## Contributing 1. Fork it ( https://github.com/piotrmurach/tty-cursor/fork ) 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create a new Pull Request This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. ## Code of Conduct Everyone interacting in the Strings::Inflection project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/piotrmurach/tty-cursor/blob/master/CODE_OF_CONDUCT.md). ## Copyright Copyright (c) 2015 Piotr Murach. See LICENSE for further details. tty-cursor-0.7.1/LICENSE.txt0000644000175000017500000000205513620101243015327 0ustar gabstergabsterCopyright (c) 2015 Piotr Murach MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. tty-cursor-0.7.1/CHANGELOG.md0000644000175000017500000000420413620101243015313 0ustar gabstergabster# Change log ## [v0.7.1] - 2020-01-25 ### Changed * Change gemspec to include metadata and remove test files ## [v0.7.0] - 2019-05-27 ### Added * Add #scroll_up & #scroll_down display by one line ### Changed * Change to restrict gem to Ruby >= 2.0 ## [v0.6.1] - 2019-02-28 ### Changed * Change gemspec to load files without git ## [v0.6.0] - 2018-07-13 ### Changed * Remove encoding magic comments ### Fixed * Fix #clear_line_before/after to use correct control symbols by Xinyue Lu(@msg7086) * Fix gem vendoring by moving version file to its own folder ## [v0.5.0] - 2017-08-01 ### Changed * Change #save & #restore to work on major systems by Austin Blatt[@austb] ## [v0.4.0] - 2017-01-08 ### Added * Add #clear_char for erasing characters * Add #clear_line_before for erasing line before the cursor * Add #clear_line_after for erasing line after the cursor * Add #column to move the cursor horizontally in the current line * Add #row to move the cursor vertically in the current column ### Changed * Remove #move_start * Change #next_line to move the cursor to beginning of the line * Change #clear_line to move the cursor to beginning of the line * Change alias_method to alias ### Fixed * Fix #clear_line to correctly clear whole line ## [v0.3.0] - 2016-05-21 ### Fixed * Fix prev_line to work in iTerm2 and Putty by @m-o-e ## [v0.2.0] - 2015-12-28 ### Changed * Change #clear_lines to clear first and move up/down ## [v0.1.0] - 2015-11-28 * Initial implementation and release [v0.7.0]: https://github.com/piotrmurach/tty-cursor/compare/v0.7.0...v0.7.1 [v0.7.0]: https://github.com/piotrmurach/tty-cursor/compare/v0.6.1...v0.7.0 [v0.6.1]: https://github.com/piotrmurach/tty-cursor/compare/v0.6.0...v0.6.1 [v0.6.0]: https://github.com/piotrmurach/tty-cursor/compare/v0.5.0...v0.6.0 [v0.5.0]: https://github.com/piotrmurach/tty-cursor/compare/v0.4.0...v0.5.0 [v0.4.0]: https://github.com/piotrmurach/tty-cursor/compare/v0.3.0...v0.4.0 [v0.3.0]: https://github.com/piotrmurach/tty-cursor/compare/v0.2.0...v0.3.0 [v0.2.0]: https://github.com/piotrmurach/tty-cursor/compare/v0.1.0...v0.2.0 [v0.1.0]: https://github.com/piotrmurach/tty-cursor/compare/v0.1.0