Skip to content

Command Prompt opens twice #146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
55f2cd9
Initial construction of the python-run-terminal package
Dec 31, 2016
ef1d41f
Prepare 0.6.3 release
Dec 31, 2016
8ff4c76
Initial construction of the python-run-terminal package
Dec 31, 2016
ccd8915
Prepare 0.6.4 release
Dec 31, 2016
2869175
Initial construction of the python-run-terminal package
Dec 31, 2016
7520d5a
Initial construction of the python-run-terminal package
Dec 31, 2016
0b7aee8
Prepare 1.0.0 release
Dec 31, 2016
691d784
Initial construction of the python-run-terminal package
Dec 31, 2016
5b3c088
Prepare 1.0.1 release
Dec 31, 2016
048c82b
Bug in run_python_code
Dec 31, 2016
d0fcefa
Prepare 1.0.2 release
Dec 31, 2016
8f3355f
Bug in run_python_code and add xfce4-terminal support
Jan 2, 2017
d174dc1
Prepare 1.0.3 release
Jan 2, 2017
2cb7a66
Fix an issue of terminal auto-close behavior on Mint and other Ubuntu…
Mar 28, 2017
364ddc0
CHANGELOG cosmetics
Mar 28, 2017
755a628
change child process to bash
tpatrascu Jun 15, 2017
0232626
change shell to bash
tpatrascu Jun 15, 2017
e4228b3
Merge pull request #2 from tpatrascu/master
jacquexgithub Jun 29, 2017
277f3e8
Merge pull request #1 from twdragon/master
jacquexgithub Jun 29, 2017
0dff4c0
Support for terminals in Windows and Linux
jacquexgithub Jan 10, 2018
1830be4
CHANGELOG cosmetics
jacquexgithub Jan 10, 2018
aff6efb
Prepare 1.1.0 release
jacquexgithub Jan 10, 2018
9a67e74
Prepare 1.1.1 release
jacquexgithub Jan 10, 2018
dce6302
Prepare 1.1.2 release
jacquexgithub Jan 10, 2018
03414b5
CHANGELOG cosmetics
jacquexgithub Jan 10, 2018
500a4af
CHANGELOG cosmetics
jacquexgithub Jan 10, 2018
e06b009
Prepare 1.1.3 release
jacquexgithub Jan 10, 2018
0c5dc8b
Correction of errors and addition of the missing file run_python_code…
jacquexgithub Jan 14, 2018
783d2ed
Prepare 1.1.4 release
jacquexgithub Jan 14, 2018
ac3ceb2
Correction of errors and addition of the missing file run_python_code…
jacquexgithub Jan 14, 2018
7dd2007
Correction of errors and addition of the missing file run_python_code…
jacquexgithub Jan 14, 2018
052ddaa
CHANGELOG cosmetics
jacquexgithub Jan 14, 2018
2df79b0
Prepare 1.1.8 release
jacquexgithub Jan 14, 2018
03a0895
CHANGELOG cosmetics
jacquexgithub Jan 14, 2018
8ac5116
Prepare 1.1.7 release
jacquexgithub Jan 14, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
build

.DS_Store
npm-debug.log
node_modules
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2016 <Your name here>
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
Expand Down
41 changes: 24 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
Binary file removed bin/cp.exe
Binary file not shown.
Binary file removed bin/libgcc_s_dw2-1.dll
Binary file not shown.
43 changes: 43 additions & 0 deletions bin/run_python_code.bat
Original file line number Diff line number Diff line change
@@ -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%
32 changes: 32 additions & 0 deletions bin/run_python_code.sh
Original file line number Diff line number Diff line change
@@ -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
6 changes: 0 additions & 6 deletions keymaps/atom-python-run.json

This file was deleted.

6 changes: 6 additions & 0 deletions keymaps/python-run-terminalnx.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
60 changes: 0 additions & 60 deletions lib/atom-python-run.js

This file was deleted.

116 changes: 116 additions & 0 deletions lib/python-run-terminalnx.js
Original file line number Diff line number Diff line change
@@ -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.");
}
}
19 changes: 14 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Binary file added resources/preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading