<commit_before>require 'canis/core/widgets/textpad'
require 'canis/core/widgets/applicationheader'
require 'fileutils'

# A file or array viewer.
#
# CHANGES
#   - 2014-04-09 - 00:58 changed textview to textpad 
# Can be used for print_help_page
# SUGGESTIONS WELCOME.
# NOTE: since this is not a proper class / object, it is being hacked to pieces
#  We need to either make this a proper class, or else make another one with a class,
#  and use this for simple purposes only. 

module Canis
  # a data viewer for viewing some text or filecontents
  # view filename, :close_key => KEY_ENTER
  # send data in an array
  # view Array, :close_key => KEY_ENTER, :layout => [23,80,0,0] (ht, wid, top, left)
  # when passing layout reserve 4 rows for window and border. So for 2 lines of text
  # give 6 rows.
  class Viewer
    # @param filename as string or content as array
    # @yield textview object for further configuration before display
    def self.view what, config={}, &block  #:yield: textview
      case what
      when String # we have a path
        content = _get_contents(what)
      when Array
        content = what
      else
        raise ArgumentError, "Viewer: Expecting Filename or Contents (array), but got #{what.class} "
      end
      wt = 0 # top margin
      wl = 0 # left margin
      wh = Ncurses.LINES-wt # height, goes to bottom of screen
      ww = Ncurses.COLS-wl  # width, goes to right end
      layout = { :height => wh, :width => ww, :top => wt, :left => wl } 
      if config.has_key? :layout
        layout = config[:layout]
        case layout
        when Array
          #wt, wl, wh, ww = layout
          # 2014-04-27 - 11:22 changed to the same order as window, otherwise confusion and errors
          wh, ww, wt, wl = layout
          layout = { :height => wh, :width => ww, :top => wt, :left => wl } 
        when Hash
          # okay
        end
      end<commit_msg>some fixes related to Document in textpad<commit_after>require 'canis/core/widgets/textpad'
require 'canis/core/widgets/applicationheader'
require 'fileutils'

# A file or array viewer.
#
# CHANGES
#   - 2014-04-09 - 00:58 changed textview to textpad 
# Can be used for print_help_page
# SUGGESTIONS WELCOME.
# NOTE: since this is not a proper class / object, it is being hacked to pieces
#  We need to either make this a proper class, or else make another one with a class,
#  and use this for simple purposes only. 

module Canis
  # a data viewer for viewing some text or filecontents
  # view filename, :close_key => KEY_ENTER
  # send data in an array
  # view Array, :close_key => KEY_ENTER, :layout => [23,80,0,0] (ht, wid, top, left)
  # when passing layout reserve 4 rows for window and border. So for 2 lines of text
  # give 6 rows.
  class Viewer
    # @param filename as string or content as array
    # @yield textview object for further configuration before display
    def self.view what, config={}, &block  #:yield: textview
      case what
      when String # we have a path
        content = _get_contents(what)
      when Array
        content = what
      when TextDocument
        $log.debug "  setting content to textdocument #{what.options.keys} "
        content = what
        #content = what.text
        #config[:content_type] = what.content_type
      else
        raise ArgumentError, "Viewer: Expecting Filename or Contents (array), but got #{what.class} "
      end
      wt = 0 # top margin
      wl = 0 # left margin
      wh = Ncurses.LINES-wt # height, goes to bottom of screen
      ww = Ncurses.COLS-wl  # width, goes to right end
      layout = { :height => wh, :width => ww, :top => wt, :left => wl } 
      if config.has_key? :layout
        layout = config[:layout]
        case layout
        when Array
          #wt, wl, wh, ww = layout
          # 2014-04-27 - 11:22 changed to the same order as window, otherwise confusion and errors
          wh, ww, wt, wl = layout
          layout = { :height => wh, :width => ww, :top => wt, :left => wl } 
        when Hash
          # okay
        end
      end
{'fraction_non_alphanumeric': 0.08833661417322834, 'fraction_numerical': 0.0172244094488189, 'mean_word_length': 2.4922680412371134, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '640374', 'n_tokens_mistral': 1293, 'n_tokens_neox': 1201, 'n_words': 505}