<commit_before>ConstructDiscoverer = require './construct/discoverer'
EventEmitter = require('events').EventEmitter
util = require 'util'
keypress = require 'keypress'
require 'sugar'
colors = require 'colors'
ansi = require 'ansi'
tty = require 'tty'

stdin = process.stdin

module.exports = class ServiceSelector extends EventEmitter

  constructor: () ->
    @services = new ConstructDiscoverer()
    @selected_index = 0
    @cursor = ansi(process.stdout)
    stdin.setRawMode(true)
    stdin.resume()
    stdin.setEncoding( 'utf8' )
    keypress(stdin)

    stdin.on 'data', @onKeyData
    stdin.on 'keypress', @onKeyPress

    for k in ["Up", "Down"]
      @services.on("service#{k}", @render)
    @render()


  render: =>
    # Update the services menu
    width = process.stdout.getWindowSize()[0]
    `util.print("\u001b[2J\u001b[0;0H")`
    @cursor.hide().write "Select a Printer:\n"
    max = @services.list.length - 1
    @selected_index = max if @selected_index > max
    @selected_index = 0 if @selected_index < 0

    for service, i in @services.list
      selected = i == @selected_index
      prefix = if selected then ">" else " "
      info = service.address<commit_msg>Added red [ENTER] to select prompt<commit_after>ConstructDiscoverer = require './construct/discoverer'
EventEmitter = require('events').EventEmitter
util = require 'util'
keypress = require 'keypress'
require 'sugar'
colors = require 'colors'
ansi = require 'ansi'
tty = require 'tty'

stdin = process.stdin

module.exports = class ServiceSelector extends EventEmitter

  constructor: () ->
    @services = new ConstructDiscoverer()
    @selected_index = 0
    @cursor = ansi(process.stdout)
    stdin.setRawMode(true)
    stdin.resume()
    stdin.setEncoding( 'utf8' )
    keypress(stdin)

    stdin.on 'data', @onKeyData
    stdin.on 'keypress', @onKeyPress

    for k in ["Up", "Down"]
      @services.on("service#{k}", @render)
    @render()


  render: =>
    # Update the services menu
    width = process.stdout.getWindowSize()[0]
    `util.print("\u001b[2J\u001b[0;0H")`
    @cursor
      .hide()
      .write("Select a Printer with ")
      .red()
      .write("[ENTER]")
      .white()
      .write(":\n")
    max = @services.list.length - 1
    @selected_index = max if @selected_index > max
    @selected_index = 0 if @selected_index < 0

    for service, i in @services.list
      selected = i == @selected_index
      prefix = if selected then ">" else " "
      info = service.address
{'fraction_non_alphanumeric': 0.1342983514274226, 'fraction_numerical': 0.012062726176115802, 'mean_word_length': 3.2675814751286447, 'pattern_counts': {'":': 1, '<': 5, '<?xml version=': 0, '>': 11, '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': '4411697', 'n_tokens_mistral': 822, 'n_tokens_neox': 805, 'n_words': 202}