diff --git a/.gitignore b/.gitignore index 1a353f5..6287bfb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ build -.DS_Store npm-debug.log node_modules diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f1b18e..e58d3cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,22 @@ +## v1.1.7 +* Bug in the file load run_python_code.bat on Windows +* Bugs in the passage of arguments from the command line + +## v1.1.3 +* Support for Windows and Linux +* Select a terminal through a drop-down list +* Optional pause when finishing the execution of a program + +## v1.0.4 +* Fix shell issue for Ubuntu 16.04LTS based distributions + +## v1.0.3 +* Fix bug: run_python_code.sh interpret it with sh no with bash +* Add support for xfce4-terminal + +## v1.0.0 +* Initial version of python-run-terminalnx package + ## 0.6.2 * Fix bug: Uncaught TypeError: Cannot read property 'path' of null diff --git a/LICENSE.md b/LICENSE.md index 5f3f537..66a670a 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,4 +1,4 @@ -Copyright (c) 2016 +Copyright (c) 2018 Jaime Dávila Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/README.md b/README.md index 58ec897..fe6a35a 100644 --- a/README.md +++ b/README.md @@ -1,32 +1,39 @@ -# atom-python-run package -[![GitHub issues](https://img.shields.io/github/issues/foreshadow/atom-python-run.svg?style=plastic)](https://github.com/foreshadow/atom-python-run/issues) -[![GitHub stars](https://img.shields.io/github/stars/foreshadow/atom-python-run.svg?style=plastic)](https://github.com/foreshadow/atom-python-run/stargazers) -[![GitHub forks](https://img.shields.io/github/forks/foreshadow/atom-python-run.svg?style=plastic)](https://github.com/foreshadow/atom-python-run/network) -[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=plastic)](https://raw.githubusercontent.com/foreshadow/atom-python-run/master/LICENSE.md) +# python-run-terminalnx package +[![GitHub issues](https://img.shields.io/github/issues/jacquexgithub/python-run-terminalnx.svg?style=plastic)](https://github.com/jacquexgithub/python-run-terminalnx/issues) +[![GitHub stars](https://img.shields.io/github/stars/jacquexgithub/python-run-terminalnx.svg?style=plastic)](https://github.com/jacquexgithub/python-run-terminalnx/stargazers) +[![GitHub forks](https://img.shields.io/github/forks/jacquexgithub/python-run-terminalnx.svg?style=plastic)](https://github.com/jacquexgithub/python-run-terminalnx/network) +[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=plastic)](https://github.com/jacquexgithub/python-run-terminalnx/master/LICENSE.md) -Run your python source file (.py) using `F5` or `F6`! - -![](https://cloud.githubusercontent.com/assets/2712675/18710388/9a665ed8-8037-11e6-803a-35e4555e89d0.jpg) +Run your python source file (.py) on Windows or Linux, using `F5` or `F6`! +![Screenshot](https://github.com/jacquexgithub/python-run-terminalnx/blob/master/resources/preview.png?raw=true "Preview") # Prerequisite -- Windows -- Add the directory of python.exe to ```PATH```. +- Add the directory of `python` (or the intended interpreter) to ```PATH```. # Method of use 1. Open a .py file. 2. Hit `F5` or `F6` to run. - - **It will save the file in current editor immediately without a confirmation, be aware.** + - **It will save the file in current editor immediately without a confirmation, be aware.** # Features -- Using `python.exe` - - Almost the same console with python IDLE, which provides syntax error and runtime error messages. -- CodeBlocks debug console style - - Shows return value and execution time - - It is a rough time based on real time rather than CPU kernel time or CPU user time -- New an issue if you have any idea of new features. +- Using `python` + - Almost the same console/terminal with python IDLE, which provides syntax error and runtime error messages. +- Shows the colored return value. Blue when the program ends successfully and red otherwise. +- Make a `pause` + - You can disable the default pause after finishing the execution of a program. +- Python Command Line Arguments + - You can pass command line arguments to your python scripts. + +# Compatibility + +- Cross Platform Compatible + - Runs on Windows, and Linux +- True Arbitrary Execution + - Global python is the default interpreter + ![A screenshot of your package](https://f.cloud.github.com/assets/69169/2290250/c35d867a-a017-11e3-86be-cd7c5bf3ff9b.gif) diff --git a/bin/cp.exe b/bin/cp.exe deleted file mode 100644 index 6d7232a..0000000 Binary files a/bin/cp.exe and /dev/null differ diff --git a/bin/libgcc_s_dw2-1.dll b/bin/libgcc_s_dw2-1.dll deleted file mode 100644 index 9e32dc2..0000000 Binary files a/bin/libgcc_s_dw2-1.dll and /dev/null differ diff --git a/bin/run_python_code.bat b/bin/run_python_code.bat new file mode 100755 index 0000000..ddb08f1 --- /dev/null +++ b/bin/run_python_code.bat @@ -0,0 +1,43 @@ +@echo off +setlocal ENABLEDELAYEDEXPANSION +REM spawn the child +REM it's tricky because shift doesn't affect %*, so hack it out +REM https://en.wikibooks.org/wiki/Windows_Batch_Scripting#Command-line_arguments +set file_python=%1 +set args=%2 + +set on_p=_-:ON PAUSE:-_ +set b_pause=true +echo %args% | findstr /R /C:"\<*%on_p%\>" 1> nul +if %ERRORLEVEL% == 1 ( + set b_pause=false +) + +set args=%args::@:=" "% +if !b_pause! == true ( + set args=%args: "_-:ON PAUSE:-_"=% +) else ( + set args=%args: "_-:OFF PAUSE:-_"=% +) + +if !args! == "" ( + python %file_python% +) else ( + set args=%args:"_-:ON PAUSE:-_"=% + set args=%args:"_-:OFF PAUSE:-_"=% + python %file_python% %args% +) +echo: +echo: +if %ERRORLEVEL%==0 ( + echo:================================= + echo:^(The programa exited with code: %ERRORLEVEL%^) +) else ( + echo:================================= + echo:^(The programa exited with code: %ERRORLEVEL%^) +) + +if %b_pause% == true ( + pause +) +exit %ERRORLEVEL% diff --git a/bin/run_python_code.sh b/bin/run_python_code.sh new file mode 100755 index 0000000..d70ddc9 --- /dev/null +++ b/bin/run_python_code.sh @@ -0,0 +1,32 @@ +#!/bin/bash +oldIFS=$IFS +IFS='' +arg_l_c=() +IFS="|" read -a la <<< "$2"; +for ((i = 0; i < ${#la[@]}; ++i)) do + if [ "${la[i]}" != "" ]; then + if [ "${la[i]}" == "_-:ON PAUSE:-_" ] || [ "${la[i]}" == "_-:OFF PAUSE:-_" ]; then + do_pause="${la[i]}" + else + arg_l_c+=("${la[i]}") + fi + fi +done + +python "$1" ${arg_l_c[@]} + +if [ $? -eq 0 ]; then + echo -e " + +\e[1;36m================================= +(The program exited with code: $?)\e[0m" +else + echo -e " + +\e[1;31m================================= +(The program exited with code: $?)\e[0m" +fi +if [ "$do_pause" == "_-:ON PAUSE:-_" ]; then + read -rsp $'Press any key to continue...\n' -n 1 key +fi +IFS=$old_IFS diff --git a/keymaps/atom-python-run.json b/keymaps/atom-python-run.json deleted file mode 100644 index 06ffd68..0000000 --- a/keymaps/atom-python-run.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "atom-text-editor": { - "f5": "Python run: run", - "f6": "Python run: run" - } -} diff --git a/keymaps/python-run-terminalnx.json b/keymaps/python-run-terminalnx.json new file mode 100755 index 0000000..829814b --- /dev/null +++ b/keymaps/python-run-terminalnx.json @@ -0,0 +1,6 @@ +{ + "atom-text-editor": { + "f5": "Python run in a command line terminal: run", + "f6": "Python run in a command line terminal: run" + } +} diff --git a/lib/atom-python-run.js b/lib/atom-python-run.js deleted file mode 100644 index e284e84..0000000 --- a/lib/atom-python-run.js +++ /dev/null @@ -1,60 +0,0 @@ -/* global atom */ -"use strict"; - -const path = require("path"); -const child_process = require("child_process"); - -module.exports = { - activate: () => { - atom.commands.add("atom-text-editor", "Python run: run", run); - }, - config: { - disable_notifications: { - title: "Disable notifications of success", - description: "Disable notifications of saving and running", - type: "boolean", - default: false - }, - disable_notifications_on_fail: { - title: "Disable notifications of failure", - description: "Disable notifications of extension name does not match", - type: "boolean", - default: false - } - } -}; - -function run() { - var editor = atom.workspace.getActiveTextEditor(); - if (!editor) { - return; - } - var file = editor.buffer.file; - if (!file) { - //if (!atom.config.get("atom-python-run.disable_notifications_on_fail")) { - atom.notifications.add("warning", "You have to create the file first."); - //} - return; - } - if (!atom.config.get("atom-python-run.disable_notifications")) { - atom.notifications.add("info", "Saving..."); - } - editor.save(); - var info = path.parse(file.path); - if (info.ext != ".py") { - if (!atom.config.get("atom-python-run.disable_notifications_on_fail")) { - atom.notifications.add("warning", info.base + " is not a .py file, exit."); - } - return; - } - if (!atom.config.get("atom-python-run.disable_notifications")) { - atom.notifications.add("info", "Running " + info.base + " ..."); - } - var child = child_process.spawn("cmd", [ - "/c", "start", __dirname + "/../bin/cp.exe", "python.exe", "\"" + file.path + "\"" - ], { - cwd: info.dir, - detached: true - }); - child.unref(); -} diff --git a/lib/python-run-terminalnx.js b/lib/python-run-terminalnx.js new file mode 100755 index 0000000..ada5d5a --- /dev/null +++ b/lib/python-run-terminalnx.js @@ -0,0 +1,116 @@ +/* global atom */ +"use strict"; + +const path = require("path"); +const child_process = require("child_process"); + +module.exports = { + activate: () => { + atom.commands.add("atom-text-editor", "Python run in a command line terminal: run", run); + }, + config: { + a_terminal_selection: { + title: "Select the command line terminal", + description: "For Windows, select `cmd` and for Linux, select the compatible terminal emulators like `gnome-terminal, konsole, xfce4-terminal, deepin-terminal or terminator`", + type: "string", + default: "cmd", + enum: [ + {value: 'cmd', description: 'cmd. Windows command line interpreter'}, + {value: 'gnome-terminal', description: 'gnome-terminal. Terminal emulator for GNOME Desktop Environment'}, + {value: 'konsole', description: 'konsole. Terminal emulator for KDE Desktop Environment'}, + {value: 'xfce4-terminal', description: 'xfce4-terminal. Terminal emulator for XFCE Desktop Environment'}, + {value: 'deepin-terminal', description: 'deepin-terminal. Terminal emulator for Deepin Desktop Environment'}, + {value: 'terminator', description: 'terminator. Terminal emulator for any Desktop Environment'} + ] + }, + b_pause: { + title: 'Pause', + description: 'Show a pause at the finish of program execution', + type: 'boolean', + default: true + }, + command_line_arguments: { + title: "Python Command Line Arguments", + description: "Enter the arguments separated by the pipe symbol (|). For example: `this is a string|7|1.82|True`", + type: "string", + default:"" + }, + disable_notifications: { + title: "Disable notifications of success", + description: "Disable notifications of saving and running", + type: "boolean", + default: false + }, + disable_notifications_on_fail: { + title: "Disable notifications of failure", + description: "Disable notifications of extension name does not match", + type: "boolean", + default: false + } + } +}; + +function run() { + var editor = atom.workspace.getActiveTextEditor(); + if (!editor) { + return; + } + var file = editor.buffer.file; + if (!file) { + atom.notifications.add("warning", "You have to create the file first."); + return; + } + + var sel_term = atom.config.get("python-run-terminalnx.a_terminal_selection"); + if (!atom.config.get("python-run-terminalnx.disable_notifications")) { + atom.notifications.add("info", "Saving..."); + } + editor.save(); + + var info = path.parse(file.path); + if (info.ext != ".py") { + if (!atom.config.get("python-run-terminalnx.disable_notifications_on_fail")) { + atom.notifications.add("warning", info.base + " is not a .py file, exit."); + } + return; + } + if (!atom.config.get("python-run-terminalnx.disable_notifications")) { + atom.notifications.add("info", "Running " + info.base + " ..."); + } + var c_l_a = atom.config.get("python-run-terminalnx.command_line_arguments") + var b_pause = atom.config.get("python-run-terminalnx.b_pause") + + if (b_pause){ + c_l_a += "|" + "_-:ON PAUSE:-_"; + }else{ + c_l_a += "|" + "_-:OFF PAUSE:-_"; + atom.notifications.add("warning", "Running the program without pause at the end."); + } + if ('win32' === process.platform) { + var n_c_l_a = c_l_a.replace(/\|/g, ":@:"); + var child = child_process.spawn(sel_term, [ + "/S", "/C", "start", __dirname + "\\..\\bin\\run_python_code.bat", file.path, n_c_l_a + ]); + child.on('error', function(err) { + atom.notifications.add("error", sel_term + " is not a command line terminal installed in the system."); + }); + child.unref(); + } else if ('linux' === process.platform) { + var ex_op = "-x"; + if (sel_term != "gnome-terminal" && sel_term != "xfce4-terminal" && sel_term != "terminator") { + var ex_op = "-e"; + } + var child = child_process.spawn(sel_term, [ + ex_op, "/bin/bash", __dirname + "/../bin/run_python_code.sh", file.path, c_l_a + ], { + cwd: info.dir, + detached: true + }); + child.on('error', function(err) { + atom.notifications.add("error", sel_term + " is not a command line terminal installed in the system."); + }); + child.unref(); + } else { + atom.notifications.add("error", process.platform + " is not a supported operating system."); + } +} diff --git a/package.json b/package.json index 9af69b3..787a2f5 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,21 @@ { - "name": "atom-python-run", - "main": "./lib/atom-python-run.js", - "version": "0.6.2", + "name": "python-run-terminalnx", + "main": "./lib/python-run-terminalnx.js", + "version": "1.1.7", "description": "Run a python source file.", "keywords": [ - "python" + "python", + "terminal", + "gnome-terminal", + "konsole", + "xfce4-terminal", + "deepin-terminal", + "terminator", + "cmd", + "linux", + "windows" ], - "repository": "https://github.com/foreshadow/atom-python-run", + "repository": "https://github.com/jacquexgithub/python-run-terminalnx", "license": "MIT", "engines": { "atom": ">=1.0.0 <2.0.0" diff --git a/resources/preview.png b/resources/preview.png new file mode 100755 index 0000000..10f0241 Binary files /dev/null and b/resources/preview.png differ diff --git a/src/cp.cpp b/src/cp.cpp deleted file mode 100644 index 3698f34..0000000 --- a/src/cp.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include -#include -#include -#include - -int main(int argc, char *argv[]) -{ - char cmd[4096]; - strcpy(cmd, "title "); // prepend title - for (int i = 1; i < argc; i++) { - strcat(cmd, argv[i]); - strcat(cmd, " "); - } - system(cmd); // reset title - int t = clock(); - int r = system(cmd + 6); // origin command - t = clock() - t; - printf("\n" - "Process returned %d (0x%X) execution time : %.3f s\n" - /*"Press any key to continue.\n"*/, - r, r, t / 1000.); - system("pause"); - return r; -}