예제 #1
0
    def handle(self, *args, **options):

        try:
            from pygments import lexers
        except ImportError:
            self.stdout.write("This command requires Pygments package.")
            self.stdout.write("Please install it with:\n\n")
            self.stdout.write("  pip install Pygments\n\n")
            return

        # Invocation examples
        _process("bash_curl", lexers.BashLexer())
        _process("bash_wget", lexers.BashLexer())
        _process("browser", lexers.JavascriptLexer())
        _process("crontab", lexers.BashLexer())
        _process("node", lexers.JavascriptLexer())
        _process("python_urllib2", lexers.PythonLexer())
        _process("python_requests", lexers.PythonLexer())
        _process("php", lexers.PhpLexer())
        _process("powershell", lexers.shell.PowerShellLexer())
        _process("powershell_inline", lexers.shell.BashLexer())
        _process("ruby", lexers.RubyLexer())

        # API examples
        _process("list_checks_request", lexers.BashLexer())
        _process("list_checks_response", lexers.JsonLexer())
        _process("create_check_request_a", lexers.BashLexer())
        _process("create_check_request_b", lexers.BashLexer())
        _process("update_check_request_a", lexers.BashLexer())
        _process("update_check_request_b", lexers.BashLexer())
        _process("create_check_response", lexers.JsonLexer())
        _process("pause_check_request", lexers.BashLexer())
        _process("pause_check_response", lexers.JsonLexer())
        _process("delete_check_request", lexers.BashLexer())
예제 #2
0
 def handle(self, *args, **options):
     _process("bash.txt", "bash.html", lexers.BashLexer())
     _process("browser.txt", "browser.html", lexers.JavascriptLexer())
     _process("crontab.txt", "crontab.html", lexers.BashLexer())
     _process("python.txt", "python.html", lexers.PythonLexer())
     _process("php.txt", "php.html", lexers.PhpLexer())
     _process("node.txt", "node.html", lexers.JavascriptLexer())
예제 #3
0
    def handle(self, *args, **options):

        try:
            from pygments import lexers
        except ImportError:
            self.stdout.write("This command requires the Pygments package.")
            self.stdout.write("Please install it with:\n\n")
            self.stdout.write("  pip install Pygments\n\n")
            return

        # Invocation examples
        _process("bash_curl", lexers.BashLexer())
        _process("bash_wget", lexers.BashLexer())
        _process("browser", lexers.JavascriptLexer())
        _process("crontab", lexers.BashLexer())
        _process("cs", lexers.CSharpLexer())
        _process("node", lexers.JavascriptLexer())
        _process("go", lexers.GoLexer())
        _process("python_urllib2", lexers.PythonLexer())
        _process("python_requests", lexers.PythonLexer())
        _process("python_requests_fail", lexers.PythonLexer())
        _process("python_requests_start", lexers.PythonLexer())
        _process("python_requests_payload", lexers.PythonLexer())
        _process("php", lexers.PhpLexer())
        _process("powershell", lexers.shell.PowerShellLexer())
        _process("powershell_inline", lexers.shell.BashLexer())
        _process("ruby", lexers.RubyLexer())
예제 #4
0
def _get_lexer(codesyntax):
    if codesyntax in ("cpp", "javascript"):
        return lexers.JavascriptLexer()
    elif codesyntax == "python":
        return lexers.PythonLexer()
    elif codesyntax == "json":
        return lexers.JsonLexer()
    elif codesyntax == "xml" or codesyntax == "html":
        return lexers.HtmlLexer()
    elif codesyntax == "yml" or codesyntax == "yaml":
        return lexers.YamlLexer()
    elif codesyntax == "css":
        return lexers.CssLexer()
    elif codesyntax == "sql":
        return lexers.SqlLexer()
    elif codesyntax == "bash" or codesyntax == "sh":
        return lexers.BashLexer()
    elif codesyntax == "go":
        return lexers.GoLexer()
    elif codesyntax == "diff":
        return lexers.DiffLexer()
    elif codesyntax == "emacslisp":
        return lexers.EmacsLispLexer()
    elif codesyntax == "lisp":
        return lexers.CommonLispLexer()
    elif codesyntax == "rust":
        return lexers.RustLexer()
    elif codesyntax == "jsx":
        return BabylonLexer()
    elif codesyntax:
        raise NotImplementedError(codesyntax)
    else:
        return lexers.TextLexer()
예제 #5
0
    def handle(self, *args, **options):

        try:
            from pygments import lexers
        except ImportError:
            self.stdout.write("This command requires Pygments package.")
            self.stdout.write("Please install it with:\n\n")
            self.stdout.write("  pip install Pygments\n\n")
            return

        _process("bash.txt", "bash.html", lexers.BashLexer())
        _process("browser.txt", "browser.html", lexers.JavascriptLexer())
        _process("crontab.txt", "crontab.html", lexers.BashLexer())
        _process("python.txt", "python.html", lexers.PythonLexer())
        _process("php.txt", "php.html", lexers.PhpLexer())
        _process("powershell.txt", "powershell.html",
                 lexers.shell.PowerShellLexer())
        _process("node.txt", "node.html", lexers.JavascriptLexer())
예제 #6
0
class EditorScreen(Screen):
    row_num = ObjectProperty(None)
    col_num = ObjectProperty(None)
    text_input_area = ObjectProperty(None)
    file_name_input = ObjectProperty(None)
    language_mode_chooser = ObjectProperty(None)
    dashboard = ObjectProperty(None)
    toggle_btn_file_chooser = ObjectProperty(None)
    lexer_dict = DictProperty({
        "Plain text": lexers.get_lexer_by_name("text"),
        "C": lexers.CLexer(),
        "C++": lexers.CppLexer(),
        "CSS": lexers.CssLexer(),
        "HTML": lexers.HtmlLexer(),
        "JavaScript": lexers.JavascriptLexer(),
        "Kivy": KivyLexer(),
        "Rust": lexers.RustLexer(),
        "Python": lexers.PythonLexer(),
        "Python3": lexers.Python3Lexer(),
        "SASS": lexers.SassLexer(),
        "SCSS": lexers.ScssLexer(),
    })

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.set_syntax_highlight(tuple(self.lexer_dict.keys())[0])
        self.text_input_area.bind(cursor=self.on_cursor)
        self.language_mode_chooser.bind(text=self.on_lang_mode_chooser)
        self.file_path = ""
        self.progress_popup = None
        self.gen_to_progress = None

    def on_cursor(self, instance, cursor):
        # cursor[0]: current cursor postition(col)
        # cursor[1]: current cursor postition(row)
        self.col_num.text = str(cursor[0])
        self.row_num.text = str(cursor[1] + 1)

    def on_lang_mode_chooser(self, instance, text):
        self.set_syntax_highlight(text)

    def set_syntax_highlight(self, language):
        self.text_input_area.lexer = self.lexer_dict[language]

    def toggle_file_chooser_show(self):
        if self.toggle_btn_file_chooser.state == "normal":
            # self.dashboard_file_chooser = None
            self.dashboard.clear_widgets()
            self.dashboard.size_hint_x = None
            self.dashboard.width = 0
        elif self.toggle_btn_file_chooser.state == "down":
            self.dashboard.add_widget(
                DashBoardFileChooserView(file_chooser_user=self))
            self.dashboard.size_hint_x = 0.4

    def clear_text(self):
        self.text_input_area.text = ""

    def save_file(self, file_path):
        with open(file_path, "w") as f:
            f.write(self.text_input_area.text)
        self.file_path = file_path
        return True

    def show_save(self):
        def close():
            if self.toggle_btn_file_chooser.state == "down":
                self.toggle_btn_file_chooser.state = "normal"
                self.toggle_file_chooser_show()
                # self.toggle_btn_file_chooser.state = "down"
                # self.toggle_file_chooser_show()

        popup = SaveFilePopup(self.save_file, close)
        popup.open()

    def open_file_yield_progress(self, file_path, *args):
        progress_max = 0
        progress_count = 0
        try:
            with open(file_path, "r") as f:
                progress_max = sum(1 for line in open(file_path, "r")) + 1
                yield progress_count, progress_max
                text = ""
                for line in f:
                    text += line
                    progress_count += 1
                    yield progress_count, progress_max
                self.text_input_area.text = text
                self.file_name_input.text = Path(file_path).parts[-1]
                self.file_path = file_path
                progress_count += 1
                yield progress_count, progress_max
        except PermissionError:
            self.text_input_area.text = (":( Permisson denined: {}".format(
                Path(file_path).parts[-1]))
            yield progress_max, progress_max
        except UnicodeDecodeError:
            self.text_input_area.text = (":( Unicode decode error: {}".format(
                Path(file_path).parts[-1]))
            yield progress_max, progress_max

    def open_file(self, file_path):
        try:
            with open(file_path, "r") as f:
                text = ""
                for line in f:
                    text += line
                self.text_input_area.text = text
                self.file_name_input.text = Path(file_path).parts[-1]
                self.file_path = file_path
        except PermissionError:
            self.text_input_area.text = (":( Permisson denined: {}".format(
                Path(file_path).parts[-1]))
        except UnicodeDecodeError:
            self.text_input_area.text = (":( Unicode decode error: {}".format(
                Path(file_path).parts[-1]))
        else:
            return True

    def update_progress_popup(self, dt):
        try:
            value, max_value = next(self.gen_to_progress)
            self.progress_popup.set_progress_max(max_value)
            self.progress_popup.set_progress_value(value)
            # --- This code For speeding up to opening file.
            if dt == 0:
                dt = -1
            else:
                dt = 0
            # ---
            Clock.schedule_once(self.update_progress_popup, dt)
        except StopIteration:
            Clock.unschedule(self.show_progress_schedule)
            self.progress_popup.dismiss()

    def open_file_with_progress(self, file_path):
        self.progress_popup = ProgressPopup()
        self.gen_to_progress = self.open_file_yield_progress(file_path)
        self.show_progress_schedule = Clock.schedule_interval(
            self.update_progress_popup, 0)

    def show_open(self):
        open_file_popup = OpenFilePopup(self.open_file_with_progress)
        open_file_popup.open()

    def show_license(self):
        save_file_popup = LicensePopup()
        save_file_popup.open()