<commit_before>import json
import os

from urwid import Columns, Pile, Text, WidgetWrap

from ubuntui.utils import Color, Padding
from ubuntui.widgets.buttons import submit_btn
from ubuntui.widgets.hr import HR
from ubuntui.widgets.input import (
    IntegerEditor,
    PasswordEditor,
    StringEditor,
    YesNo
)


class StepWidget(WidgetWrap):
    INPUT_TYPES = {
        'text': StringEditor(),
        'password': PasswordEditor(),
        'boolean': YesNo(),
        'integer': IntegerEditor()
    }

    def __init__(self, app, step_model, cb):
        """
        Arguments:
        step_model: step model
        step_model_widget: step model widget
        cb: callback
        """
        self.app = app
        self.model = step_model

        self.title = Text(('info_minor', step_model.title))
        self.description = Text(('info_minor', step_model.description))
        self.result = Text(step_model.result)
        self.output = Text(('info_minor', ''))
        self.icon = Text(("info_minor", "\N{BALLOT BOX}"))
        self.has_error = False

        self.additional_input = []
        if len(step_model.additional_input) > 0:
            for i in step_model.additional_input:
                widget = {
                    "label": Text(('body', i['label'])),
                    "key": i['key'],
                    "input": self.INPUT_TYPES.get(i['type']),
                }
                if 'default' in i:
                    widget['input'] = StringEditor(default=i['default'])

                self.additional_input.append(widget)
        else:
            widget = {
                "label": Text(""),
                "key": "submit",
                "input": None
            }
            self.additional_input.append(widget)

        self.cb = cb
        self.step_pile = self.build_widget()
        self.show_output = True
        super().__init__(self.step_pile)

    def __repr__(self):
        return "<StepWidget: {}>".format(self.model.title)

    def update(self):
        if not self.show_output:
            return
        if not os.path.exists(self.model.path + ".out"):
            return
        with open(self.model.path + ".out") as outf:
            lines = outf.readlines()
            if len(lines) < 1:
                return
            result = json.loads(lines[-1])
            self.output.set_text(('body', "\n    " +
                                  result['message']))

    def clear_output(self):
        self.output.set_text("")

    def set_description(self, description, color='info_minor'):
        self.description.set_text(
            (color, description))

    def set_error(self, error_msg):
        self.error.set_text(
            ('error_major', error_msg))

    def set_icon_state(self, result_code):
        """ updates status icon

        Arguments:
        icon: icon widget<commit_msg>remove unneeded function<commit_after>import json
import os

from urwid import Columns, Pile, Text, WidgetWrap

from ubuntui.utils import Color, Padding
from ubuntui.widgets.buttons import submit_btn
from ubuntui.widgets.hr import HR
from ubuntui.widgets.input import (
    IntegerEditor,
    PasswordEditor,
    StringEditor,
    YesNo
)


class StepWidget(WidgetWrap):
    INPUT_TYPES = {
        'text': StringEditor(),
        'password': PasswordEditor(),
        'boolean': YesNo(),
        'integer': IntegerEditor()
    }

    def __init__(self, app, step_model, cb):
        """
        Arguments:
        step_model: step model
        step_model_widget: step model widget
        cb: callback
        """
        self.app = app
        self.model = step_model

        self.title = Text(('info_minor', step_model.title))
        self.description = Text(('info_minor', step_model.description))
        self.result = Text(step_model.result)
        self.output = Text(('info_minor', ''))
        self.icon = Text(("info_minor", "\N{BALLOT BOX}"))
        self.has_error = False

        self.additional_input = []
        if len(step_model.additional_input) > 0:
            for i in step_model.additional_input:
                widget = {
                    "label": Text(('body', i['label'])),
                    "key": i['key'],
                    "input": self.INPUT_TYPES.get(i['type']),
                }
                if 'default' in i:
                    widget['input'] = StringEditor(default=i['default'])

                self.additional_input.append(widget)
        else:
            widget = {
                "label": Text(""),
                "key": "submit",
                "input": None
            }
            self.additional_input.append(widget)

        self.cb = cb
        self.step_pile = self.build_widget()
        self.show_output = True
        super().__init__(self.step_pile)

    def __repr__(self):
        return "<StepWidget: {}>".format(self.model.title)

    def update(self):
        if not self.show_output:
            return
        if not os.path.exists(self.model.path + ".out"):
            return
        with open(self.model.path + ".out") as outf:
            lines = outf.readlines()
            if len(lines) < 1:
                return
            result = json.loads(lines[-1])
            self.output.set_text(('body', "\n    " +
                                  result['message']))

    def clear_output(self):
        self.output.set_text("")

    def set_description(self, description, color='info_minor'):
        self.description.set_text(
            (color, description))

    def set_icon_state(self, result_code):
        """ updates status icon

        Arguments:
        icon: icon widget
{'fraction_non_alphanumeric': 0.12053967690395881, 'fraction_numerical': 0.0010651517841292384, 'mean_word_length': 1.8454545454545455, 'pattern_counts': {'":': 12, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4093871', 'n_tokens_mistral': 1656, 'n_tokens_neox': 1571, 'n_words': 343}