lib/gloo/objs/basic/text.rb in gloo-0.4.0 vs lib/gloo/objs/basic/text.rb in gloo-0.5.0
- old
+ new
@@ -1,17 +1,20 @@
# Author:: Eric Crane (mailto:eric.crane@mac.com)
# Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
#
# A [multiline] block of text.
#
+require 'tty-editor'
+require 'tty-pager'
module Gloo
module Objs
class Text < Gloo::Core::Obj
KEYWORD = 'text'.freeze
KEYWORD_SHORT = 'txt'.freeze
+ DEFAULT_TMP_FILE = 'tmp.txt'.freeze
#
# The name of the object type.
#
def self.typename
@@ -53,13 +56,34 @@
#
# Get a list of message names that this object receives.
#
def self.messages
- return super
+ return super + %w[edit page]
end
+ #
+ # Show the contents of the file, paginated.
+ #
+ def msg_page
+ return unless value
+
+ # pager = TTY::Pager::SystemPager.new command: 'less -R'
+ pager = TTY::Pager.new
+ pager.page( value )
+ end
+
+ #
+ # Edit the text in the default editor.
+ #
+ def msg_edit
+ tmp = File.join( $settings.tmp_path, DEFAULT_TMP_FILE )
+ File.open( tmp, 'w' ) { |file| file.write( self.value ) }
+ TTY::Editor.open( tmp )
+ set_value File.read( tmp )
+ end
+
# ---------------------------------------------------------------------
# Help
# ---------------------------------------------------------------------
#
@@ -76,10 +100,11 @@
CHILDREN
None
MESSAGES
- None
+ edit - Edit the text field in the default editor.
+ page - Show the text, paginated.
TEXT
end
end
end