diff --git a/.classpath b/.classpath index 41c9857..03f7996 100644 --- a/.classpath +++ b/.classpath @@ -12,7 +12,4 @@ - - - diff --git a/.gitignore b/.gitignore index e92bd93..4e46b85 100644 --- a/.gitignore +++ b/.gitignore @@ -26,10 +26,8 @@ build/tmp/ # test scripts test.bat target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst -*.class target/ *.lst -*.class -target/classes/main/java/jterm/test.bat -.project + +*.class \ No newline at end of file diff --git a/.project b/.project index e30130a..50c189e 100644 --- a/.project +++ b/.project @@ -10,8 +10,14 @@ + + org.eclipse.m2e.core.maven2Builder + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs index f9fe345..e9441bb 100644 --- a/.settings/org.eclipse.core.resources.prefs +++ b/.settings/org.eclipse.core.resources.prefs @@ -1,4 +1,3 @@ eclipse.preferences.version=1 encoding//src/main/java=UTF-8 -encoding//src/test/java=UTF-8 encoding/=UTF-8 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 6249222..ec4300d 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,12 +1,5 @@ eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.compliance=1.7 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.source=1.7 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs deleted file mode 100644 index f897a7f..0000000 --- a/.settings/org.eclipse.m2e.core.prefs +++ /dev/null @@ -1,4 +0,0 @@ -activeProfiles= -eclipse.preferences.version=1 -resolveWorkspaceProjects=true -version=1 diff --git a/.travis.yml b/.travis.yml index 6b30b71..71585ac 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,4 @@ language: java jdk: - oraclejdk8 notifications: - slack: sergix:qb9AYlJo8QqPybBY1FQ5V6my - -# before_script: chmod +x compile.sh + slack: sergix:qb9AYlJo8QqPybBY1FQ5V6my \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..de2a843 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.configuration.updateBuildConfiguration": "automatic" +} \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 70dd0ce..57266a0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,9 +6,36 @@ These guidelines should be reviewed before contributing to the JTerm project. ## About JTerm is a cross-platform terminal. The project is written in Java so that it can be run on virtually any computer. This document provides information such as project resources, guidelines, and other information needed to start programming for JTerm. +## Implementation +This project is written in Java using [Eclipse IDE for Java EE](http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/neon3). + ## Code of Conduct The Code of Conduct for any contributions and posting information can be found [here](/CODE_OF_CONDUCT.md). +## GitHub Branch +The development branch of the JTerm project is the `dev` branch. _**Make sure to work off of this branch, not the master!**_ All commits on the dev branch are tracked in the 'Dev' PR. This is the PR that is merged into master. + +## Builds +Once you build a file from the source code to an archive (.jar), push it to the /build/jar folder, along with the associated changelog (see Changelog section), source code (see Source Code section), and documentation (see Documentation section.) + +The format of the archive's filename is as follows: "jterm-v(build version).jar" + +## Source Code +Keep all updated and current source code in the /src directory, which should be updated with every build. Please review the [Source Code Style Guide](https://github.com/Sergix/JTerm/blob/master/docs/SourceStyleGuide.md) for more information. + +Subfolders are formatted for packaging and for CI integration. + +When pushing the source code with a build, DO NOT change the filenames. As mentioned in the "Builds" section, package the source code with every build into a ".zip" file and a Wrapfile that should be placed in the /build/src directory when pushing a build. Subfolders in the /src directory (e.g. /src/main/java/...) should be included in packaged source. Wrapfiles should only include sources in the `main/` source directory. The format for the file should be as follows: `jterm-src-v(version).zip`, and `jterm-src-v(version).wrap`. + +## Versioning +Version numbers should use [Semantic Versioning](https://github.com/mojombo/semver/blob/master/semver.md). +Numbering versions on files (such as released builds) should take the format of "vX.Y.Z", where "X.Y.Z" is the version. + +## Documentation +Documentation is published with every: +- Major and minor release ([Documentation Style Guide](https://github.com/Sergix/JTerm/blob/master/docs/DocStyleGuide.md)) +- Patch ([Patch Notes Documentation Style Guide](https://github.com/Sergix/JTerm/blob/master/docs/PatchDocStyleGuide.md)) + ## Styling Source code, documentation, and patch note styling can be found here: - [Source Code Style Guide](https://github.com/Sergix/JTerm/blob/master/docs/SourceStyleGuide.md) @@ -18,7 +45,36 @@ Source code, documentation, and patch note styling can be found here: Any of these types of files MUST be formatted as shown in these documents. ## Changelog -Any changes, in any branch, MUST be pushed to the changelog file found on the dev branch called "changelog.txt". View the "Changelog" section in the [README](/README.md) for more information. Do not push updates to changelog files on other branches; the dev one is to be the only one changed and updated. +Every time an update is pushed, the changelog will be updated and pushed as well. It is highly recommended that every time you build you update the changelog. + +Once you add something to the changelog, DO NOT remove the entry, unless if, and only if, it is incorrect (such as a typo in the version number.) If you change a previous entry you must include a statement stating your change in a seperate entry. + +The global changelog file is in the root folder of the project and is named "changelog.txt"; EVERY note will go into this file. It is also required that when you push a build you push an associated changelog file, formatted "jterm-changelog-(build version).txt". This file should be pushed to the /build/changelog directory. + +Changelog entry headings must be formatted as shown in the given example below. New changelog entries in the global "changelog.txt" file should be placed at the _top_ of the file, not the bottom. Simply create a few newlines before the latest entry and use the newlines to enter the new entry information. Entries must also be tab-indented. + +The format for a changelog entry is as follows: +``` +(#(entry))[MM/DD/YYYY-HH:MM (version) (username)] + (entry contents) + (entry contents) + (blank newline) +``` +Here is an example changelog: +``` +(#2)[2/2/2017-3:33 1.3 NCSGeek] + information uploaded. + added files. + pushed to github. + +(#1)[1/1/2017-3:33 1.0 Sergix] + information uploaded. + pushed to github. + +``` +Of course, a real changelog would be more descriptive in its entries. + +Timestamps should be in 24-hour (aka military) time. ## Pull Requests Pull Requests, of course, MUST be opened on a new branch. The branch and PR name must be short but descriptive of its topic. A description must be made of the PR's purpose and a short description of the added code. Every PR must request to be reviewed by @Sergix or @NCSGeek. Travis CI is also used in this project (dashboard can be found [here](https://travis-ci.org/Sergix/JTerm)), and PR's are automatically checked by Travis CI to make sure they are ready to be deployed. @@ -34,5 +90,7 @@ If a new bug or issue is found, create a new Issue! The issue name must be short - Version of JTerm 3. "Files and Code" - If you find where the issue is or believe it to be, put the filenames and/or code in this section. -## Source Code -When contributing new source code, edit the files contained in the `/src/main/java/jterm` directory. Create new files as shown in the [Source Code Style Guide](https://github.com/Sergix/JTerm/blob/master/docs/DocStyleGuide.md). The editor used can be any of your choosing, but we recommend [Eclipse](http://www.eclipse.org/). Do not create new directories unless required and given permission by @Sergix or @NCSGeek. +> JTerm 0.4.0 +> `jterm-v0.4.0.jar` +> This project and its source are held under the GNU General Public License, located in the LICENSE file in the project's directory. +> (c) 2017 \ No newline at end of file diff --git a/README.md b/README.md index ea33c2a..816b7cd 100644 --- a/README.md +++ b/README.md @@ -2,67 +2,24 @@ ![Build Status](https://travis-ci.org/Sergix/JTerm.svg?branch=master) -## Definition -A terminal written for cross-platform usge. +## What is it? +A terminal written for cross-platform usage. -## Implementation -This project is written in Java using [Eclipse IDE for Java EE](http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/neon3). +## Why will it help me? +Because the JTerm project is written in Java, this provides it various advantages: +- System compatibility downsides don't exist! +- Much safer than C++/C and other system languages -## Contributing -View the [Contributing Guidelines](https://github.com/Sergix/JTerm/blob/master/CONTRIBUTING.md) for more information. The JTerm project is open to anyone and any code! - -## Builds -Once you build a file from the source code to an archive (.jar), push it to the /build/jar folder, along with the associated changelog (see Changelog section), source code (see Source Code section), and documentation (see Documentation section.) -The format of the archive's filename is as follows: "jterm-v(build version).jar" - -## Source Code -Keep all updated and current source code in the /src directory, which should be updated with every build. -Please review the [Source Code Style Guide](https://github.com/Sergix/JTerm/blob/master/docs/SourceStyleGuide.md) for more information. -Subfolders are formatted for packaging and for CI integration. -When pushing the source code with a build, DO NOT change the filenames. -As mentioned in the "Builds" section, package the source code with every build into a ".zip" file and a Wrapfile that should be placed in the /build/src directory when pushing a build. Subfolders in the /src directory (e.g. /src/main/java/...) should be included in packaged source. Wrapfiles should only include sources in the `main/` source directory. -The format for the file should be as follows: `jterm-src-v(version).zip`, and `jterm-src-v(version).wrap`. - -## Changelog -Every time an update is pushed, the changelog will be updated and pushed as well. -It is highly recommended that every time you build you update the changelog. Once you add something to the changelog, DO NOT remove the entry, unless if, and only if, it is incorrect (such as a typo in the version number.) If you change a previous entry you must include a statement stating your change in a seperate entry. -The global changelog file is in the root folder of the project and is named "changelog.txt"; EVERY note will go into this file. It is also required that when you push a build you push an associated changelog file, formatted "jterm-changelog-(build version).txt". This file should be pushed to the /build/changelog directory. -Changelog entry headings must be formatted as shown in the given example below. -New changelog entries in the global "changelog.txt" file should be placed at the _top_ of the file, not the bottom. Simply create a few newlines before the latest entry and use the newlines to enter the new entry information. Entries must also be tab-indented. -The format for a changelog entry is as follows: -``` -(#(entry))[MM/DD/YYYY-HH:MM (version) (username)] - (entry contents) - (entry contents) - (blank newline) -``` -Here is an example changelog: -``` -(#2)[2/2/2017-3:33 1.3 NCSGeek] - information uploaded. - added files. - pushed to github. +Plus, it's open source, so if you find any issues, you can help out everyone else using JTerm! -(#1)[1/1/2017-3:33 1.0 Sergix] - information uploaded. - pushed to github. +## Where do I get it? +Check the [releases](https://github.com/Sergix/JTerm/releases) page for binaries, as well as the source code. You can also look in the `/builds` directory for changelogs and other build-related stuff. -``` -Of course, a real changelog would be more descriptive in its entries. - -Timestamps should be in 24-hour (aka military) time. - -## Versioning -Version numbers should use [Semantic Versioning](https://github.com/mojombo/semver/blob/master/semver.md). -Numbering versions on files (such as released builds) should take the format of "vX.Y.Z", where "X.Y.Z" is the version. - -## Documentation -Documentation is published with every: -- Major and minor release ([Documentation Style Guide](https://github.com/Sergix/JTerm/blob/master/docs/DocStyleGuide.md)) -- Patch ([Patch Notes Documentation Style Guide](https://github.com/Sergix/JTerm/blob/master/docs/PatchDocStyleGuide.md)) +## How can I help? +View the [Contributing Guidelines](https://github.com/Sergix/JTerm/blob/master/CONTRIBUTING.md) for more information. The JTerm project is open to anyone and any code! ## Slack -The JTerm project now has a Slack messaging group! Request to join the [Sergix](https://sergix.slack.com/) team to recieve notifications on updates, Travis CI build status, and more on the #jterm channel. +The JTerm project now has a Slack messaging group! Request to join the [Sergix](https://sergix.slack.com/) team to recieve notifications on updates, Travis CI build status, and more! > JTerm 0.4.0 > `jterm-v0.4.0.jar` diff --git a/build.bat b/build.bat new file mode 100644 index 0000000..3bc9a11 --- /dev/null +++ b/build.bat @@ -0,0 +1,6 @@ +@echo off +cls + +rd /S /Q target + +mvn clean package \ No newline at end of file diff --git a/build/changelog/jterm-changelog-v0.4.1.txt b/build/changelog/jterm-changelog-v0.4.1.txt new file mode 100644 index 0000000..1ea4458 --- /dev/null +++ b/build/changelog/jterm-changelog-v0.4.1.txt @@ -0,0 +1,54 @@ +Changelog entry: + +(#76)[9/8/2017-18:55 0.4.1 Sergix] + Updated CONTRIBUTING.md with branch information. + Changed POM project version to 0.4.1. + Built binaries for version 0.4.1. + Wrote patch notes and compiled the full changelog. + Pushed updates to Git. + +Full changes include: + - Created Pause class + - Pause.java + - Contains all code previously located in Exec that was associated with the `pause` command + - `EnterPause(options)`: pauses the interpreter until the Enter key is hit. + - Created Set class + - Set.java + - Contains all code previously located in Exec that was associated with the `set` command + - `set` now can be called from outside Exec + - `vars`: global program hashtable containing all variables + - `NewVar(options)`: creates a new variable + - `PrintVars()`: prints all variables currently stored + - Window class changes + - Added `Window.CloseAll()` function (JTerm automatically calls `CloseAll()` right before exiting the application) + - `Window.windows` array contains all active windows + - Created batch scripts for build and run processes + - `init.bat`: initializes the environment for building + - `build.bat`: builds with Maven (`mvn clean package`) + - `run.bat`: runs the application + - The Maven package process now builds two JAR's: one w/o dependencies and one with. + - If you perform the `run` batch script right after a build, it will rename the files to their respective names + - Packaged JAR, no dependencies (before name change w/ `run`): `jterm-0.5.0.jar` + - Packaged JAR, with dependencies (before name change w/ `run`): `jterm-0.5.0-jar-with-dependencies.jar` + - Packaged JAR, no dependencies (after name change w/ `run`): `jterm-0.5.0-no-deps.jar` + - Packaged JAR, with dependencies (after name change w/ `run`): `jterm-v0.5.0.jar` + - `Files.WriteFile()` input stream is closed when a blank line is entered + - Moved all non-JTerm-compatible switch cases from `Exec.Parse()` into `JTerm.Parse()` + - Added documentation comments for multiple functions + - Updated README and CONTRIBUTING + - Deleted the `Dir` and `readfile` branches + - Updated the POM to include build process changes + - Maven now runs a special plugin that packages all dependencies into the binary (maven-assembly-plugin) + - Merged [#17](https://github.com/Sergix/JTerm/pull/17). Thanks to @d4nntheman! + - Fixed [#14](https://github.com/Sergix/JTerm/issues/14) + - Fixed [#15](https://github.com/Sergix/JTerm/issues/15) + - Fixed [#16](https://github.com/Sergix/JTerm/issues/16) + - Fixed [#20](https://github.com/Sergix/JTerm/issues/20) + - Minor Bug Fixes + - `NewDir()` was not taking arguments with multiple spaces + - `WriteFile()` was not taking arguments with multiple spaces + - `Delete()` was not taking arguments with multiple spaces + - `Echo()` was outputting an extra space + - `ChangeDir()` accepts directory paths enclosed in quotes + +More information provided in published patch notes documentation. \ No newline at end of file diff --git a/build/jar/jterm-v0.4.1.jar b/build/jar/jterm-v0.4.1.jar new file mode 100644 index 0000000..9e5046c Binary files /dev/null and b/build/jar/jterm-v0.4.1.jar differ diff --git a/build/src/jterm-src-v0.4.1.wrap b/build/src/jterm-src-v0.4.1.wrap new file mode 100644 index 0000000..8639639 --- /dev/null +++ b/build/src/jterm-src-v0.4.1.wrap @@ -0,0 +1,1796 @@ +###% jterm-src-v0.4.1.wrap wrapper-windows-v1.1 + +###* Client.java + +/* +* JTerm - a cross-platform terminal +* Copyright (C) 2017 Sergix, NCSGeek +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. + +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. + +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +package main.java.jterm; + +import java.io.*; +import java.net.Socket; +import java.util.ArrayList; + +public class Client implements Runnable +{ + + private static BufferedReader input; + + public void run() + { + + while (true) + { + try + { + String output = Client.input.readLine(); + if (output != null) + System.out.println(output); + + } + catch (IOException ioe) + { + return; + + } + + } + + } + + public static void Connect(ArrayList options) + { + + String address = "0.0.0.0"; + String portInput = "80"; + boolean next = false; + + for (String option: options) + { + if (option.equals("-h")) + { + System.out.println("Command syntax:\n\tconnect [-h] [-p port] address\n\nConnect to the specified IP address using TCP/IP. Default address is \"0.0.0.0\". Default port is 80."); + return; + + } + else if (option.equals("-p")) + next = true; + + else if (next) + { + portInput = option; + next = false; + + } + else + address = option; + + } + + int i = 0; + int port = 0; + + while( i < portInput.length()) + { + port *= 10; + port += portInput.charAt(i++) - '0'; + + } + + try + { + System.out.println("Connecting to " + address + ":" + port); + + Socket connection = new Socket(address, port); + InputStream input = connection.getInputStream(); + OutputStream output = connection.getOutputStream(); + BufferedReader bufferedSocketInput = new BufferedReader(new InputStreamReader(input)); + + Client.input = bufferedSocketInput; + + Client client = new Client(); + Thread readThread = new Thread(client); + readThread.start(); + + System.out.println("Connected to server. Enter a blank line to quit. Reading for input..."); + + while (true) + { + BufferedReader bufferedSocketOutput = new BufferedReader(new InputStreamReader(System.in), 1); + String line = bufferedSocketOutput.readLine(); + + if (line.equals("")) + break; + + output.write(line.getBytes()); + + output.close(); + bufferedSocketOutput.close(); + + } + + connection.close(); + + } + catch (IOException ioe) + { + System.out.println("Connection severed."); + + } + + } + +} + +###* Dir.java + +/* +* JTerm - a cross-platform terminal +* Copyright (C) 2017 Sergix, NCSGeek +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. + +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. + +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +package main.java.jterm; + +import java.io.*; +import java.util.ArrayList; + +public class Dir +{ + + /* + * PrintDir() void + * + * Prints the contents of a specified directory + * to a file. + * + * ArrayList options - command options + * + * -f + * Changes the output format to only file + * and directory names + * -h + * Prints help information + * directory + * Prints this directory rather than the + * current working directory. + * + * Examples + * + * PrintDir(options); + * => [Contents of "dir/"] + * => F RW myFile.txt 2 KB + */ + public static void PrintDir(ArrayList options) throws NullPointerException + { + + String path = JTerm.currentDirectory; + boolean printFull = true; + + for (String option: options) + { + if (option.equals("-f")) + printFull = false; + + else if (option.equals("-h")) + { + System.out.println("Command syntax:\n\tdir [-f] [-h] [directory]\n\nPrints a detailed table of the current working directory's subfolders and files."); + return; + + } + else + path = option; + + } + + File dir = new File(path); + File[] files = dir.listFiles(); + + /* + * Format of output: + * [FD] [RWHE] [filename] [size in KB] + * + * Prefix definitions: + * F -- File + * D -- Directory + * R -- Readable + * W -- Writable + * H -- Hidden + * + * Example: + * F RW myfile.txt 5 KB + */ + + System.out.println("[Contents of \"" + path + "\"]"); + for (File file: files) + { + if (printFull) + System.out.println("\t" + (file.isFile() ? "F " : "D ") + (file.canRead() ? "R" : "") + (file.canWrite() ? "W" : "") + (file.isHidden() ? "H" : "") + "\t" + file.getName() + (file.getName().length() < 8 ? "\t\t\t" : (file.getName().length() > 15 ? "\t" : "\t\t")) + (file.length() / 1024) + " KB"); + + else + System.out.println("\t" + file.getName()); + + } + + } + + + /* + * ChangeDir() void + * + * Changes the working directory to the specified + * input. + * + * -h + * Prints help information + * directory + * Path to change the working directory to. + * + * ArrayList options - command options + */ + public static void ChangeDir(ArrayList options) + { + + String newDirectory = ""; + + for (String option: options) + { + if (option.equals("-h")) + { + System.out.println("Command syntax:\n\tcd [-h] directory\n\nChanges the working directory to the path specified."); + return; + + } + else + newDirectory += option + " "; + + } + + newDirectory = newDirectory.trim(); + + if (newDirectory.startsWith("\"") && newDirectory.endsWith("\"")) + { + newDirectory = newDirectory.substring(1, newDirectory.length()); + newDirectory = newDirectory.substring(0, newDirectory.length() - 1); + + } + + if (newDirectory.equals("")) + { + System.out.println("Path not specified. Type \"cd -h\" for more information."); + return; + + } + + // Test if the input exists and if it is a directory + File dir = new File(newDirectory); + File newDir = new File(JTerm.currentDirectory + newDirectory); + + if (newDirectory.equals("/")) + newDirectory = "/"; + + else if (newDir.exists() && newDir.isDirectory()) + newDirectory = JTerm.currentDirectory + newDirectory; + + else if ((!dir.exists() || !dir.isDirectory()) && (!newDir.exists() || !newDir.isDirectory())) + { + System.out.println("ERROR: Directory \"" + newDirectory + "\" is either does not exist or is not a valid directory."); + return; + + } + + if (!newDirectory.endsWith("/")) + newDirectory += "/"; + + // It does exist, and it is a directory, so just change the global working directory variable to the input + JTerm.currentDirectory = newDirectory; + + } + + /* + * PrintWorkingDir() void + * + * Prints the working directory to the console. + * + * -h + * Prints help information + * + * ArrayList options - command options + */ + public static void PrintWorkingDir(ArrayList options) + { + + for (String option: options) + { + if (option.equals("-h")) + { + System.out.println("Command syntax:\n\tpwd\n\nPrints the current Working Directory."); + return; + + } + + } + + // Simply print the currentDirectory variable to the console + System.out.println(JTerm.currentDirectory); + + } + + /* + * NewDir() void + * + * Creates a new directory. + * + * -h + * Prints help information + * + * ArrayList options - command options + */ + public static void NewDir(ArrayList options) + { + + String name = ""; + + for (String option: options) + { + if (option.equals("-h")) + { + System.out.println("Command syntax:\n\tmd [-h] name\n\nCreates a new directory."); + return; + + } + else + name += option + " "; + + } + + name = name.trim(); + name = JTerm.currentDirectory + name; + + File dir = new File(name); + dir.mkdir(); + } + +} + +###* Echo.java + +/* +* JTerm - a cross-platform terminal +* Copyright (C) 2017 Sergix, NCSGeek +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. + +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. + +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +package main.java.jterm; + +import java.util.ArrayList; + +public class Echo +{ + + /* + * EchoInput() void + * + * Echoes the input recieved to the console. + * + * ArrayList options - command options + * + * -h + * Prints help information. + */ + public static void EchoInput(ArrayList options) + { + + String output = ""; + + for (String option: options) + { + if (option.equals("-h")) + { + System.out.println("Command syntax:\n\techo [-h] input\n\nPrints the specified input to the console."); + return; + + } + else + output += option + " "; + + } + + output = output.substring(0, output.length() - 1); + System.out.println(output); + + } + +} + +###* Exec.java + +/* +* JTerm - a cross-platform terminal +* Copyright (C) 2017 Sergix, NCSGeek +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +package main.java.jterm; + +import java.io.*; +import java.util.ArrayList; +import java.util.Scanner; + +public class Exec +{ + + /* + * Run() boolean + * + * Runs the executable file. + * + * ArrayList options - command options + */ + public static boolean Run(ArrayList options) + { + + String file = ""; + + for (String option: options) { + if (option.equals("-h")) + { + System.out.println("Command syntax:\n\texec [-h] file\n\nExecutes a batch script."); + return false; + + } + else + file = option; + + } + + File script = new File(file); + if (!script.exists() || !script.isFile()) + { + file = JTerm.currentDirectory + file; + script = new File(file); + if (!script.exists() || !script.isFile()) + { + System.out.println("ERROR: File \"" + file + "\" either does not exist or is not an executable file."); + return true; + + } + + } + + try + { + BufferedReader reader = new BufferedReader(new FileReader(script)); + try + { + String directive = reader.readLine(); + if (directive != null) + do + { + // Store the command as an ArrayList + Scanner tokenizer = new Scanner(directive); + ArrayList commandOptions = new ArrayList(); + while (tokenizer.hasNext()) + options.add(tokenizer.next()); + + tokenizer.close(); + + // Where the magic happens! + JTerm.Parse(commandOptions); + + } while ((directive = reader.readLine()) != null); + + reader.close(); + + } + catch (IOException ioe) + { + System.out.println(ioe); + + } + + } + catch (FileNotFoundException ioe) + { + System.out.println(ioe); + + } + + return false; + + } + + // public static void Parse(String directive) + // { + + // switch (command) + // { + // case "pause": + + // return; + + // default: + // // for (;;) + // // if ( vars.containsKey(options.get(0)) ) + // // { + // // int value; + // // // + // // // TODO + // // // Create arithmetic operations that passes the value + // // // to whatever it is needed for + // // // + // // if ( !options.get(1).equals("=") || !vars.containsKey(options.get(2)) || !vars.containsKey(options.get(4)) ) + // // break; + + // // switch(options.get(3)) + // // { + // // case "+": + // // value = Integer.parseInt( vars.get(options.get(2)) ) + Integer.parseInt( vars.get(options.get(4)) ); + // // break; + + // // case "-": + // // value = Integer.parseInt( vars.get(options.get(2)) ) - Integer.parseInt( vars.get(options.get(4)) ); + // // break; + + // // case "*": + // // value = Integer.parseInt( vars.get(options.get(2)) ) * Integer.parseInt( vars.get(options.get(4)) ); + // // break; + + // // case "/": + // // value = Integer.parseInt( vars.get(options.get(2)) ) / Integer.parseInt( vars.get(options.get(4)) ); + // // break; + + // // default: + // // return; + + // // } + + // // //vars.replace(options.get(0), String.valueOf(value)); + + // // return; + + // // } + // // else if ( windows.containsKey(options.get(0)) ) + // // { + // // switch(options.get(1)) + // // { + // // case "visible": + // // windows.get(options.get(0)).ToggleVisible(); + // // break; + + // // case "title": + // // windows.get(options.get(0)).GetFrame().setTitle(GetRest(options, 2)); + // // break; + + // // default: + // // break; + + // // } + + // // } + // // else + + // return; + + // } + + // } + + public static String GetRest(ArrayList options, int index) + { + + String output = ""; + for (int i = index; i < options.size(); i++) + { + if (i != options.size() - 1) + output += options.get(i) + " "; + + else + output += options.get(i); + + } + + return output; + + } + +} + +###* Files.java + +/* +* JTerm - a cross-platform terminal +* Copyright (C) 2017 Sergix, NCSGeek +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +package main.java.jterm; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileWriter; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; + +public class Files +{ + + /* + * WriteFile() void + * + * Get input and write it to a file. + * Changelog (#65) + * + * ArrayList options - command options + * + * -h + * Prints help information + */ + public static void WriteFile(ArrayList options) + { + + String filename = ""; + + for (String option: options) + { + if (option.equals("-h")) + { + System.out.println("Command syntax:\n\twrite [-h] filename\n\nOpens an input prompt in which to write text to a new file."); + return; + + } + else + filename += option; + + } + + filename = filename.trim(); + filename = JTerm.currentDirectory + filename; + + if (filename.equals("")) + { + System.out.println("Error: missing filename; type \"write -h\" for more information."); + return; + + } + + try + { + System.out.println("Enter file contents (press enter after a blank line to quit):"); + String line = JTerm.userInput.readLine(); + String output = line; + + for(;;) + { + line = JTerm.userInput.readLine(); + if (line.equals("")) + break; + + else if (line.equals(" ")) + output += "\n"; + + output += "\n" + line; + + } + + FileWriter fileWriter = new FileWriter(filename); + fileWriter.write(output); + fileWriter.close(); + + } + catch (IOException ioe) + { + System.out.println(ioe); + + } + + } + + /* + * Delete() void + * + * Delete the specified file or directory. + * + * ArrayList options - command options + * + * -h + * Prints help information + */ + public static void Delete(ArrayList options) + { + + String filename = ""; + + for (String option: options) + { + if (option.equals("-h")) + { + System.out.println("Command syntax:\n\tdel [-h] file/directory\n\nDeletes the specified file or directory."); + return; + + } + else + filename += option; + + } + + filename.trim(); + filename = JTerm.currentDirectory + filename; + + File dir = new File(filename); + if (!dir.exists()) + { + System.out.println("ERROR: File/directory \"" + options.get(options.size() - 1) + "\" does not exist."); + return; + + } + + dir.delete(); + + } + + /* + * ReadFile() void + * Changelog (#68) + * + * Reads the specified files and outputs the contents + * to the console. + * + * ArrayList options - command options + * + * -h + * Prints help information + * + * Credit to @d4nntheman + */ + public static void ReadFile(ArrayList options) + { + + String filename = ""; + for (String option: options) + { + if (option.equals("-h")) + { + System.out.println("Command syntax:\n\t read [-h] [file1 file2 ...]\n\nReads and outputs the contents of the specified files."); + return; + + } + + filename = JTerm.currentDirectory + option; + File file = new File(filename); + if (!file.exists()) + { + System.out.println("ERROR: File/directory \"" + option + "\" does not exist."); + break; + + } + + try ( BufferedReader reader = new BufferedReader(new FileReader(file.getAbsolutePath())) ) + { + System.out.println("\n[JTerm - Contents of " + option + "]\n"); + String line = null; + while( (line = reader.readLine()) != null ) + System.out.println(line); + + } + catch (IOException e) + { + e.printStackTrace(); + return; + + } + + } + + } + +} + +###* JTerm.java + +/* +* JTerm - a cross-platform terminal +* Copyright (C) 2017 Sergix, NCSGeek +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +// package = folder :P +package main.java.jterm; + +import java.util.Scanner; +import java.io.*; +import java.util.ArrayList; +import java.util.Hashtable; + +public class JTerm +{ + + // Global version variable + static String version = "0.4.1"; + + // Global directory variable (use "cd" command to change) + // Default value "./" is equal to the default directory set when the program starts + static String currentDirectory = "./"; + + static String commandChars = ""; + + static Hashtable commands = new Hashtable(); + + static BufferedReader userInput = new BufferedReader(new InputStreamReader(System.in)); + + /* + * main() void + * + * Function called when the program loads. Sets + * up basic input streams and runs the command + * loop. + * + * String[] args - arguments passed from the + * console + */ + public static void main(String[] args) + { + + // Assign a default value of false to the quit variable + boolean quit = false; + + // Print licensing information + System.out.println( + "JTerm Copyright (C) 2017 Sergix, NCSGeek, chromechris\n" + + "This program comes with ABSOLUTELY NO WARRANTY.\n" + + "This is free software, and you are welcome to redistribute it\n" + + "under certain conditions.\n" + ); + + // Infinite loop for getting input + do + { + // Set return value of the input function to "quit" + quit = JTerm.Standby(); + + // As long as we are not quitting... + } while (!quit); + + // Close all open window instances + Window.CloseAll(); + + } + + /* + * Standby() boolean + * + * Awaits user command and then calls Parse() with the + * input. + * + * BufferedReader user_unput - Input stream loaded from the + * main() function + */ + public static boolean Standby() + { + + // Print the current directory as the prompt (e.g. "./") + System.out.print(JTerm.currentDirectory + " "); + String command = ""; + + // Attempt to read a line from the input + try + { + command = userInput.readLine(); + + // If the command is a blank line, loop to next + if (command.equals("")) + { + return false; + + } + + } + catch (IOException ioe) + { + System.out.println(ioe); + + // Quit because of error + return true; + + } + + // Reset the value of the input prompt char reader + commandChars = ""; + + // Get each substring of the command entered + Scanner tokenizer = new Scanner(command); + + // options String array will be passed to command functions + ArrayList options = new ArrayList(); + + // Get command arguments + while (tokenizer.hasNext()) + { + String next = tokenizer.next(); + options.add(next); + + } + + // Close the string stream + tokenizer.close(); + + // Parse the command and quit if necessary + if (Parse(options)) + return true; + + // Keep looping; we don't want to quit + return false; + + } + + /* + * Parse() boolean + * + * Checks input and passes command options to the function + * that runs the requested command. + * + * ArrayList options - command options + */ + public static boolean Parse(ArrayList options) + { + + // Get the first string in the options array, which is the command + String command = options.get(0).toLowerCase(); + + // Get rid of the command for when we pass the rest of the command options + options.remove(0); + + // Switch through command names + switch (command) + { + case "help": + // Prints "JTerm v1.0" for example + System.out.println("JTerm v" + version); + break; + + case "quit": + // Quit the program + return true; + + case "write": + Files.WriteFile(options); + break; + + case "dir": + Dir.PrintDir(options); + break; + + case "chdir": + case "cd": + Dir.ChangeDir(options); + break; + + case "pwd": + Dir.PrintWorkingDir(options); + break; + + case "echo": + Echo.EchoInput(options); + break; + + case "delete": + case "del": + Files.Delete(options); + break; + + case "md": + Dir.NewDir(options); + break; + + case "read": + Files.ReadFile(options); + break; + + /*case "connect": + Client.Connect(options); + break; + + case "server": + Server.Start(options); + break;*/ + + case "window": + new Window(options); + break; + + case "exec": + Exec.Run(options); + break; + + case "ps": + Ps.View(options); + break; + + case "ping": + Ping.PingHost(options); + break; + + case "set": + Set.NewVar(options); + break; + + case "pause": + Pause.EnterPause(options); + break; + + // Commands to skip in batch files + case "bcdedit": + case "chkdsk": + case "chkntfs": + case "cls": + case "cmd": + case "color": + case "convert": + case "diskpart": + case "driverquery": + case "format": + case "fsutil": + case "gpresult": + case "mode": + case "sc": + case "shutdown": + case "start": + case "tasklist": + case "taskkill": + case "ver": + case "vol": + case "wmic": + break; + + default: + // Create a new array that contains the command and check if it is an executable + ArrayList execFile = new ArrayList(); + execFile.add(command); + if ( Exec.Run(execFile) ) + System.out.println("Unknown Command \"" + command + "\""); + + // All else fails + break; + + } + + // Keep looping + return false; + + } + +} + +###* Pause.java + +package main.java.jterm; + +import java.util.ArrayList; +import java.io.IOException; + +public class Pause +{ + + /* + * EnterPause() void + * + * Pauses the interpreter until the Enter + * key is hit. + * + * ArrayList options - command options + */ + public static void EnterPause(ArrayList options) + { + + if (options.size() == 1) + System.out.print("Press enter to continue..."); + + else + System.out.print(Exec.GetRest(options, 1)); + + try + { + JTerm.userInput.read(); + JTerm.userInput.skip(1); + + } + catch (IOException ioe) + { + System.out.println(ioe); + + } + + } + +} + +###* Ping.java + +package main.java.jterm; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.Socket; +import java.util.ArrayList; + +/* +* Original code credit to @chromechris +* +* (edits for release done by @Sergix) +*/ +public class Ping +{ + + /* + * PingHost() void + * + * Attempts to connect to the specified host + * through the port provided. + * + * ArrayList options - command options + */ + public static void PingHost(ArrayList options) + { + + String host = "google.com", port = "80"; + boolean portNext = false; + + for (String option: options) + { + if (option.equals("-h")) + { + System.out.println("Command syntax:\n\tping [-h] [-p port] host\n\nAttempts to connect to the specified host. Default port is '80'."); + return; + + } + else if (portNext) + { + port = option; + portNext = false; + + } + else if (option.equals("-p")) + portNext = true; + + else + host = option; + + } + + try (Socket socket = new Socket()) + { + System.out.println("Pinging " + host + "..."); + socket.connect(new InetSocketAddress(host, Integer.parseInt(port)), 10000); + System.out.println("Ping Successful"); + + } + catch (IOException e) + { + // Either timeout or unreachable or failed DNS lookup + System.out.println("Ping Failed"); + + } + + } + +} + +###* Ps.java + +package main.java.jterm; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.ArrayList; + +import org.apache.commons.lang3.SystemUtils; + +/* +* Original code credit to @chromechris +* +* (edits for release done by @Sergix) +*/ +public class Ps +{ + + /* + * View() void + * + * Views all processes running on the host + * system. + * + * String[] args - arguments passed from the + * console + */ + public static void View(ArrayList options) + { + + for (String option: options) + { + if (option.equals("-h")) + { + System.out.println("Command syntax:\n\tps [-h]\n\nDisplays all current processes running on the host system."); + return; + + } + + } + + if (SystemUtils.IS_OS_LINUX) + { + try + { + String line; + Process p = Runtime.getRuntime().exec("ps -e"); + BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); + while ((line = input.readLine()) != null) + { + // Parse data here. + System.out.println(line); + + } + input.close(); + + } + catch (Exception err) + { + err.printStackTrace(); + + } + + } + else if (SystemUtils.IS_OS_WINDOWS) + { + try + { + String line; + Process p = Runtime.getRuntime().exec(System.getenv("windir") + "\\system32\\" + "tasklist.exe"); + BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); + while ((line = input.readLine()) != null) + { + // Parse data here. + System.out.println(line); + + } + + input.close(); + + } + catch (Exception err) + { + err.printStackTrace(); + + } + + } + + } + +} + +###* Server.java + +/* +* JTerm - a cross-platform terminal +* Copyright (C) 2017 Sergix, NCSGeek +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. + +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. + +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +package main.java.jterm; + +import java.io.*; +import java.net.ServerSocket; +import java.net.Socket; +import java.util.ArrayList; + +public class Server implements Runnable +{ + + private Socket socket; + public static boolean run = true; + public static int port = 0; + private static String line; + + Server(Socket newSocket) + { + + socket = newSocket; + + } + + public void run() + { + + while (run) + { + try + { + InputStream input = socket.getInputStream(); + BufferedReader bufferedSocketInput = new BufferedReader(new InputStreamReader(input)); + + line = bufferedSocketInput.readLine(); + if (line.isEmpty()) + break; + + System.out.println("\n" + line); + + bufferedSocketInput.close(); + + } + catch (IOException ioe) + { + System.out.println(ioe); + break; + + } + + } + + } + + public static void Start(ArrayList options) + { + + String portInput = "80"; + + for (String option: options) + { + if(option.equals("-h")) + { + System.out.println("Command syntax:\n\tserver [-h] port\n\nStarts a TCP server socket that accepts "); + return; + + } + else + portInput = option; + + } + + int i = 0; + + while( i < portInput.length()) + { + port *= 10; + port += portInput.charAt(i++) - '0'; + + } + + try + { + ServerSocket server = new ServerSocket(port); + + new Thread(new Runnable() + { + + public void run() + { + + while (true) + { + System.out.print("> "); + BufferedReader consoleInput = new BufferedReader(new InputStreamReader(System.in), 1); + try + { + String input = consoleInput.readLine(); + switch (input) { + case "help": + System.out.println("Server currently opened on port " + port); + break; + + case "quit": + run = false; + return; + + } + + } + catch (IOException ioe) + { + System.out.println("Input Stream closed."); + break; + + } + + } + + } + + } + ).start(); + + while (run) + { + Socket socket = server.accept(); + Server newRequest = new Server(socket); + new Thread(newRequest).start(); + + } + + server.close(); + + } + catch (IOException ioe) + { + System.out.println("ERROR: Server closed"); + + } + + } + +} + +###* Set.java + +/* +* JTerm - a cross-platform terminal +* Copyright (C) 2017 Sergix, NCSGeek +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +package main.java.jterm; + +import java.util.Hashtable; +import java.util.Enumeration; +import java.util.ArrayList; + +public class Set +{ + + // Global variable hashtable + public static Hashtable vars = new Hashtable(); + + /* + * NewVar() void + * + * Creates a new variable that is stored in + * the global vars hashtable. + * + * ArrayList options - command options + */ + public static void NewVar(ArrayList options) + { + + // Print the value of all current variables + if (options.size() == 1) + { + PrintVars(); + return; + + } + + // Get the variable name + String key = options.get(1); + + // The name can't include spaces + if ( !options.get(2).equals("=") ) + return; + + // If the type is a window, create a new one + if (options.get(3).equals("window")) + { + // Remove the 'set' word from the options list + options.remove(0); + + // Pass the rest of the options to create a new Window + Window newWindow = new Window(options); + + // Put the window ID into the vars hashtable + // associated with its key + vars.put(key, Integer.toString(newWindow.GetId())); + + // Add the window to the global list + Window.windows.add(newWindow); + + return; + + } + + // Put the variable contents into the global hashtable + vars.put(key, Exec.GetRest(options, 3)); + + } + + /* + * PrintVars() void + * + * Prints the values of all variables + * currently stored. + */ + public static void PrintVars() + { + + String element = ""; + + // For each key... + for (Enumeration e = vars.keys(); e.hasMoreElements();) + // ...print in the format of "key=value" + System.out.println((element = e.nextElement()) + "=" + vars.get(element)); + + } + +} + +###* Window.java + +/* +* JTerm - a cross-platform terminal +* Copyright (C) 2017 Sergix, NCSGeek +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. + +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. + +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +package main.java.jterm; + +import java.util.ArrayList; +import javax.swing.JFrame; + +public class Window +{ + + public static int windowCount = 0; + public static ArrayList windows = new ArrayList(); + + private int id; + private JFrame window; + private String title = null; + private boolean visible = false; + + /* + * Window() void + * + * Create a new JFrame window. + * + * ArrayList options - command options + * + * -h + * Prints help information + * + * -t title + * Sets the window title in + * the header + * + * -w width + * Sets the width of the window + * + * -l height + * Sets the height of the window + * + * -r + * Sets the window to be able to + * be resized + * + */ + Window(ArrayList options) + { + + int width = 500, height = 500; + boolean resizable = false; + + boolean titleNext = false, heightNext = false, widthNext = false; + + for (String option: options) + { + if (option.equals("-h")) + { + System.out.println("Command syntax:\t\nwindow [-h] [-r] [-v] [-w width] [-l height] [-t title]\n\nCreates a new programmable GUI window.\nDefault title is \"JTerm Window\", and the default width and height of the window is 500 x 500."); + return; + + } + else if (option.equals("-v")) + visible = true; + + else if(option.equals("-t")) + { + title = ""; + titleNext = true; + + } + else if(option.equals("-w")) + widthNext = true; + + else if(option.equals("-l")) + heightNext = true; + + else if(widthNext) + { + width = Integer.parseInt(option); + widthNext = false; + + } + + else if(heightNext) + { + height = Integer.parseInt(option); + heightNext = false; + + } + else if (option.equals("-r")) + resizable = true; + + else if(titleNext) + title += option + " "; + + } + + windowCount += 1; + id = windowCount; + + if (title == null) + title = "JTerm Window"; + + JFrame window = new JFrame(title); + window.setSize(width, height); + window.setResizable(resizable); + window.setVisible(visible); + + this.window = window; + windows.add(this); + + } + + /* + * ToggleVisible() void + * + * Toggles the visibility of the window + */ + public void ToggleVisible() + { + + window.setVisible(visible = !visible); + + } + + /* + * GetId() int + * + * Returns the process ID of the window + */ + public int GetId() + { + + return id; + + } + + /* + * GetId() JFrame + * + * Returns the JFrame object displaying + * the window + */ + public JFrame GetFrame() + { + + return this.window; + + } + + /* + * GetTitle() String + * + * Returns the title of the window + */ + public String GetTitle() + { + + return title; + + } + + public static void CloseAll() + { + + for (Window window: windows) + { + window.GetFrame().setVisible(false); //you can't see me! + window.GetFrame().dispose(); //Destroy the JFrame object + + } + + } + +} + diff --git a/build/src/jterm-src-v0.4.1.zip b/build/src/jterm-src-v0.4.1.zip new file mode 100644 index 0000000..778768e Binary files /dev/null and b/build/src/jterm-src-v0.4.1.zip differ diff --git a/changelog.txt b/changelog.txt index 6f6941b..079d2a3 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,106 @@ +(#76)[9/8/2017-19:30 0.4.1 Sergix] + Updated CONTRIBUTING.md with branch information. + Changed POM project version to 0.4.1. + Built binaries for version 0.4.1. + Wrote patch notes and compiled the full changelog. + Pushed updates to Git. + +(#75)[9/8/2017-17:56 0.4.0 Sergix] + Removed unecessary imports in multiple files. + Changed Exec error message. + Moved options tokenizer from Exec.Parse() into the Exec.Run() line processing loop, and it now calls JTerm.Parse() rather than Exec.Parse() for command processing. + Created Pause class. + - Pause.java + - EnterPause(options): pauses the interpreter until the Enter key is hit. + Moved all non-JTerm-compatible switch cases from Exec.Parse() into JTerm.Parse(). + Added documentation comments for multiple functions. + Pushed updates to Git. + +(#74)[9/8/2017-16:46 0.4.0 Sergix] + Moved all the "set" command code into its own class, Set. + - vars: global program hashtable containing all variables + - NewVar(options): creates a new variable + - PrintVars(): prints all variables currently stored + Slight improvements in efficiency in the Set command. + Set can also now be called from the regular prompt, and not just from exec files. + The next update to JTerm will probably result in a patch (v0.4.1) unless something significant is added. + Pushed updates to Git. + +(#73)[9/8/2017-13:00 0.4.0 Sergix] + Fixed an issue with the importing of the commons library in the POM. + Pushed updates to Git. + +(#72)[9/8/2017-12:47 0.4.0 Sergix] + Fixed Issue #20. + - Maven was not loading the dependencies into the output JAR. + - Added the maven-assembly-plugin to the POM. + Slight modifications to the batch build and run scripts. + The Maven package process now builds two JAR's: one w/o dependencies and one with. + - If you perform the "run" batch script right after a build, it will rename the files to their respective names. + - Packaged JAR, no dependencies (before name change w/ "run"): jterm-0.5.0.jar + - Packaged JAR, with dependencies (before name change w/ "run"): jterm-0.5.0-jar-with-dependencies.jar + - Packaged JAR, no dependencies (after name change w/ "run"): jterm-0.5.0-no-deps.jar + - Packaged JAR, with dependencies (after name change w/ "run"): jterm-v0.5.0.jar + Closed Issue #20. + Pushed updates to Git. + +(#71)[9/7/2017-21:52 0.4.0 Sergix] + Deleted the Dir and readfile branches. + Updated some stuff in the Slack group! :D + Slight changes to the POM in trying to resolve Issue #20. + Pushed updates to Git. + +(#70)[9/5/2017-21:52 0.4.0 Sergix] + Issue presented in entry #69 still present. Opening an issue on GitHub to get multiple people's input. + Updated the README and CONTRIBUTING docs (mostly just moved some stuff around.) + Added the Apache Commons Lang library to /lib, trying to figure out how to package it with Maven.... + Added "Pushed updates to Git." line in previous entry. + Pushed updates to Git. + +(#69)[9/4/2017-22:01 0.4.0 Sergix] + Time to start this project up again! It's been dormant for a while as I've been busy with other things. + I myself have moved out of the Eclipse IDE for this project, so I have made a very small "init", "build", and "run" batchfile to help me out. :P + Also, I am currently working on setting up a Vagrantfile for helping out new users who want to contribute (more info at https://www.vagrantup.com/intro/index.html). + Known Issue: + - SystemUtils lib not importing in Ps.java (POM issue?) + Pushed updates to Git. + +(#68)[7/10/2017-18:03 0.4.0 Sergix] + Merged PR #17 which included the ReadFile() function in Files.java written by @d4nntheman. + - Closes issue #16 + Slight changes to Files.ReadFile() code spacing. + Added BufferedReader to imports of Files.java (fixes Travis CI build fail). + Pushed updates to Git. + +(#67)[7/6/2017-11:25 0.4.0 Sergix] + Fixed issue #15 (2). (https://github.com/Sergix/JTerm/issues/15) + ChangeDir() accepts directory paths enclosed in quotes. + Pushed updates to Git. + +(#66)[7/6/2017-11:25 0.4.0 Sergix] + Fixed issue #15. (https://github.com/Sergix/JTerm/issues/15) + Fixed other issues: + - NewDir() was not taking arguments with multiple spaces + - WriteFile() was not taking arguments with multiple spaces + - Delete() was not taking arguments with multiple spaces + - Echo() was outputting an extra space + Pushed updates to Git. + +(#65)[7/4/2017-13:48 0.4.0 Sergix] + Updated WriteFile(); input stream is closed when a blank line is entered. + A single space on a line can be used to output a blank line into a file. + Pushed updates to Git. + +(#64)[7/4/2017-11:41 0.4.0 Sergix] + Fixed #14 (https://github.com/Sergix/JTerm/issues/14). + Added Window.CloseAll() function and the Window.windows array. + JTerm automatically calls CloseAll() right before exiting the application. + Pushed updates to Git. + +(#63)[7/3/2017-14:36 0.4.0 Sergix] + Resolved file conflicts from last push to dev branch. + Removed unecessary files and reformatted eclipse project. + (#62)[7/1/2017-19:12 0.3.1 Sergix] Preparing for v0.4.0 release. Set a longer timeout for the "ping" command. Timeout is now 10 seconds. @@ -372,4 +475,4 @@ Uploaded the global changelog file to the project. Changed README.md "Changelog" section to require username in changelog entries. New entires in the changelog must be placed at the top of the file, rather than the bottom. - Renamed my GitHub profile to simply "Sergix" rather than "Sergix7440." + Renamed my GitHub profile to simply "Sergix" rather than "Sergix7440." \ No newline at end of file diff --git a/docs/patch/jterm-v0.4.1-docs.md b/docs/patch/jterm-v0.4.1-docs.md new file mode 100644 index 0000000..676e90b --- /dev/null +++ b/docs/patch/jterm-v0.4.1-docs.md @@ -0,0 +1,64 @@ +# JTerm Patch Notes Documentation v0.4.1 + +## Table of Contents +``` +I. Table of Contents +II. Overview +III. Patch Notes +IV. Changelog +``` + +## Overview +This document provides information on version 0.4.1 of the JTerm project. Developer notes and the full changelog is included. + +## Patch Notes +Patch version "0.4.1" adds the "Set" and "Pause" classes which were previously located in Exec. Their associated commands can now be called from the interpreter. The project README and CONTRIBUTING.md has been updated with some minor changes. On the development side, batch scripts ("init", "build", and "run") have been created to assist with the build process. You can now build and run JTerm without relying on an IDE such as Eclipse, and can develop from _any_ application of your choosing. See the full changelog below for more in-depth detail. + +## Changelog +- Created Pause class + - Pause.java + - Contains all code previously located in Exec that was associated with the `pause` command + - `EnterPause(options)`: pauses the interpreter until the Enter key is hit. +- Created Set class + - Set.java + - Contains all code previously located in Exec that was associated with the `set` command + - `set` now can be called from outside Exec + - `vars`: global program hashtable containing all variables + - `NewVar(options)`: creates a new variable + - `PrintVars()`: prints all variables currently stored +- Window class changes + - Added `Window.CloseAll()` function (JTerm automatically calls `CloseAll()` right before exiting the application) + - `Window.windows` array contains all active windows +- Created batch scripts for build and run processes + - `init.bat`: initializes the environment for building + - `build.bat`: builds with Maven (`mvn clean package`) + - `run.bat`: runs the application +- The Maven package process now builds two JAR's: one w/o dependencies and one with. + - If you perform the `run` batch script right after a build, it will rename the files to their respective names + - Packaged JAR, no dependencies (before name change w/ `run`): `jterm-0.5.0.jar` + - Packaged JAR, with dependencies (before name change w/ `run`): `jterm-0.5.0-jar-with-dependencies.jar` + - Packaged JAR, no dependencies (after name change w/ `run`): `jterm-0.5.0-no-deps.jar` + - Packaged JAR, with dependencies (after name change w/ `run`): `jterm-v0.5.0.jar` +- `Files.WriteFile()` input stream is closed when a blank line is entered +- Moved all non-JTerm-compatible switch cases from `Exec.Parse()` into `JTerm.Parse()` +- Added documentation comments for multiple functions +- Updated README and CONTRIBUTING +- Deleted the `Dir` and `readfile` branches +- Updated the POM to include build process changes + - Maven now runs a special plugin that packages all dependencies into the binary (maven-assembly-plugin) +- Merged [#17](https://github.com/Sergix/JTerm/pull/17). Thanks to @d4nntheman! +- Fixed [#14](https://github.com/Sergix/JTerm/issues/14) +- Fixed [#15](https://github.com/Sergix/JTerm/issues/15) +- Fixed [#16](https://github.com/Sergix/JTerm/issues/16) +- Fixed [#20](https://github.com/Sergix/JTerm/issues/20) +- Minor Bug Fixes + - `NewDir()` was not taking arguments with multiple spaces + - `WriteFile()` was not taking arguments with multiple spaces + - `Delete()` was not taking arguments with multiple spaces + - `Echo()` was outputting an extra space + - `ChangeDir()` accepts directory paths enclosed in quotes + +> `JTerm 0.4.1` +> `jterm-v0.4.1.jar` +> This project and its source are held under the GNU General Public License, located in the LICENSE file in the project's directory. +> (c) 2017 diff --git a/init.bat b/init.bat new file mode 100644 index 0000000..172a173 --- /dev/null +++ b/init.bat @@ -0,0 +1,4 @@ +@echo off + +cls +prompt dev~JTerm/ diff --git a/libs/jnativehook-2.1.0.jar b/libs/jnativehook-2.1.0.jar deleted file mode 100644 index f9cd3b7..0000000 Binary files a/libs/jnativehook-2.1.0.jar and /dev/null differ diff --git a/pom.xml b/pom.xml index a9db60a..ef5e047 100644 --- a/pom.xml +++ b/pom.xml @@ -1,11 +1,13 @@ + 4.0.0 sergix jterm - 0.4.0 + 0.4.1 jar + JTerm is a cross-platform terminal designed for simple use and to run batch files. JTerm is hosted on GitHub by Sergix and NCSGeek. jterm http://sergix.github.io/projects/JTerm @@ -14,26 +16,6 @@ UTF-8 - - - junit - junit - 3.8.1 - test - - - junit - junit-dep - 4.10 - test - - - org.apache.commons - commons-lang3 - 3.6 - - - @@ -45,7 +27,39 @@ 1.7 + + org.apache.maven.plugins + maven-assembly-plugin + + + create-my-bundle + package + + single + + + + jar-with-dependencies + + + + + + - JTerm is a cross-platform terminal designed for simple use and to run batch files. JTerm is hosted on GitHub by Sergix and NCSGeek. - + + + + junit + junit-dep + 4.10 + test + + + org.apache.commons + commons-lang3 + 3.6 + + + \ No newline at end of file diff --git a/run.bat b/run.bat new file mode 100644 index 0000000..a727544 --- /dev/null +++ b/run.bat @@ -0,0 +1,10 @@ +@echo off + +cd target +if EXIST "jterm-0.4.1-jar-with-dependencies.jar" ( + ren jterm-0.4.1.jar jterm-0.4.1-no-deps.jar + ren jterm-0.4.1-jar-with-dependencies.jar jterm-v0.4.1.jar +) +cd .. + +java -cp target/jterm-v0.4.1.jar main.java.jterm.JTerm \ No newline at end of file diff --git a/src/main/java/jterm/Client.class b/src/main/java/jterm/Client.class deleted file mode 100644 index 22405a4..0000000 Binary files a/src/main/java/jterm/Client.class and /dev/null differ diff --git a/src/main/java/jterm/Dir.class b/src/main/java/jterm/Dir.class deleted file mode 100644 index 659b471..0000000 Binary files a/src/main/java/jterm/Dir.class and /dev/null differ diff --git a/src/main/java/jterm/Dir.java b/src/main/java/jterm/Dir.java index 6288a0e..1b93c3a 100644 --- a/src/main/java/jterm/Dir.java +++ b/src/main/java/jterm/Dir.java @@ -128,7 +128,16 @@ public static void ChangeDir(ArrayList options) } else - newDirectory = option; + newDirectory += option + " "; + + } + + newDirectory = newDirectory.trim(); + + if (newDirectory.startsWith("\"") && newDirectory.endsWith("\"")) + { + newDirectory = newDirectory.substring(1, newDirectory.length()); + newDirectory = newDirectory.substring(0, newDirectory.length() - 1); } @@ -143,7 +152,10 @@ public static void ChangeDir(ArrayList options) File dir = new File(newDirectory); File newDir = new File(JTerm.currentDirectory + newDirectory); - if (newDir.exists() && newDir.isDirectory()) + if (newDirectory.equals("/")) + newDirectory = "/"; + + else if (newDir.exists() && newDir.isDirectory()) newDirectory = JTerm.currentDirectory + newDirectory; else if ((!dir.exists() || !dir.isDirectory()) && (!newDir.exists() || !newDir.isDirectory())) @@ -153,10 +165,7 @@ else if ((!dir.exists() || !dir.isDirectory()) && (!newDir.exists() || !newDir.i } - if (newDirectory.equals("/")) - newDirectory = "/"; - - else if (!newDirectory.endsWith("/")) + if (!newDirectory.endsWith("/")) newDirectory += "/"; // It does exist, and it is a directory, so just change the global working directory variable to the input @@ -217,10 +226,13 @@ public static void NewDir(ArrayList options) } else - name = JTerm.currentDirectory + option; + name += option + " "; } + name = name.trim(); + name = JTerm.currentDirectory + name; + File dir = new File(name); dir.mkdir(); } diff --git a/src/main/java/jterm/Echo.class b/src/main/java/jterm/Echo.class deleted file mode 100644 index 7c5cd3a..0000000 Binary files a/src/main/java/jterm/Echo.class and /dev/null differ diff --git a/src/main/java/jterm/Echo.java b/src/main/java/jterm/Echo.java index 42172b0..2653f63 100644 --- a/src/main/java/jterm/Echo.java +++ b/src/main/java/jterm/Echo.java @@ -51,6 +51,7 @@ public static void EchoInput(ArrayList options) } + output = output.substring(0, output.length() - 1); System.out.println(output); } diff --git a/src/main/java/jterm/Exec.class b/src/main/java/jterm/Exec.class deleted file mode 100644 index fd99643..0000000 Binary files a/src/main/java/jterm/Exec.class and /dev/null differ diff --git a/src/main/java/jterm/Exec.java b/src/main/java/jterm/Exec.java index 55ad89f..ea69d3a 100644 --- a/src/main/java/jterm/Exec.java +++ b/src/main/java/jterm/Exec.java @@ -6,12 +6,10 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ @@ -20,18 +18,18 @@ import java.io.*; import java.util.ArrayList; -import java.util.Enumeration; -import java.util.Hashtable; import java.util.Scanner; public class Exec { - private static Hashtable vars = new Hashtable<>(); - - // var name, window object - private static Hashtable windows = new Hashtable<>(); - + /* + * Run() boolean + * + * Runs the executable file. + * + * ArrayList options - command options + */ public static boolean Run(ArrayList options) { @@ -56,7 +54,7 @@ public static boolean Run(ArrayList options) script = new File(file); if (!script.exists() || !script.isFile()) { - System.out.println("ERROR: File \"" + file + "\" either does not exist or is not a file."); + System.out.println("ERROR: File \"" + file + "\" either does not exist or is not an executable file."); return true; } @@ -72,7 +70,16 @@ public static boolean Run(ArrayList options) if (directive != null) do { - Exec.Parse(directive); + // Store the command as an ArrayList + Scanner tokenizer = new Scanner(directive); + ArrayList commandOptions = new ArrayList(); + while (tokenizer.hasNext()) + options.add(tokenizer.next()); + + tokenizer.close(); + + // Where the magic happens! + JTerm.Parse(commandOptions); } while ((directive = reader.readLine()) != null); @@ -95,181 +102,82 @@ public static boolean Run(ArrayList options) return false; } - - public static void Parse(String directive) - { - - String command = ""; - Scanner tokenizer = new Scanner(directive); - ArrayList options = new ArrayList(); - while (tokenizer.hasNext()) - options.add(tokenizer.next()); - - if (options.size() != 0) - command = options.get(0).toLowerCase(); + + // public static void Parse(String directive) + // { - else - { - tokenizer.close(); - return; - - } - - switch (command) - { - case "set": - if (options.size() == 1) - { - String element = ""; - for (Enumeration e = vars.keys(); e.hasMoreElements();) - System.out.println((element = e.nextElement()) + "=" + vars.get(element)); - - break; - - } - - String key = options.get(1); - if ( !options.get(2).equals("=") ) - { - tokenizer.close(); - return; - - } - - if (options.get(3).equals("window")) - { - for (int i = 0; i < 4; i++) - options.remove(0); - - Window newWindow = new Window(options); - vars.put(key, Integer.toString(newWindow.GetId())); - windows.put(key, newWindow); - break; - - } - - vars.put(key, GetRest(options, 3)); - break; - - case "pause": - if (options.size() == 1) - System.out.print("Press enter to continue..."); - - else - System.out.print(GetRest(options, 1)); + // switch (command) + // { + // case "pause": - try - { - JTerm.userInput.read(); - JTerm.userInput.skip(1); - - } - catch (IOException ioe) - { - System.out.println(ioe); - - } - - tokenizer.close(); - return; - - // These commands are system-level/OS-dependent and are not possible to integrate into JTerm. - // Just skip over them. - case "bcdedit": - case "chkdsk": - case "chkntfs": - case "cls": - case "cmd": - case "color": - case "convert": - case "diskpart": - case "driverquery": - case "format": - case "fsutil": - case "gpresult": - case "mode": - case "sc": - case "shutdown": - case "start": - case "tasklist": - case "taskkill": - case "ver": - case "vol": - case "wmic": - break; - - default: - for (;;) - if ( vars.containsKey(options.get(0)) ) - { - int value; - // - // TODO - // Create arithmetic operations that passes the value - // to whatever it is needed for - // - if ( !options.get(1).equals("=") || !vars.containsKey(options.get(2)) || !vars.containsKey(options.get(4)) ) - break; + // return; + + // default: + // // for (;;) + // // if ( vars.containsKey(options.get(0)) ) + // // { + // // int value; + // // // + // // // TODO + // // // Create arithmetic operations that passes the value + // // // to whatever it is needed for + // // // + // // if ( !options.get(1).equals("=") || !vars.containsKey(options.get(2)) || !vars.containsKey(options.get(4)) ) + // // break; - switch(options.get(3)) - { - case "+": - value = Integer.parseInt( vars.get(options.get(2)) ) + Integer.parseInt( vars.get(options.get(4)) ); - break; + // // switch(options.get(3)) + // // { + // // case "+": + // // value = Integer.parseInt( vars.get(options.get(2)) ) + Integer.parseInt( vars.get(options.get(4)) ); + // // break; - case "-": - value = Integer.parseInt( vars.get(options.get(2)) ) - Integer.parseInt( vars.get(options.get(4)) ); - break; + // // case "-": + // // value = Integer.parseInt( vars.get(options.get(2)) ) - Integer.parseInt( vars.get(options.get(4)) ); + // // break; - case "*": - value = Integer.parseInt( vars.get(options.get(2)) ) * Integer.parseInt( vars.get(options.get(4)) ); - break; + // // case "*": + // // value = Integer.parseInt( vars.get(options.get(2)) ) * Integer.parseInt( vars.get(options.get(4)) ); + // // break; - case "/": - value = Integer.parseInt( vars.get(options.get(2)) ) / Integer.parseInt( vars.get(options.get(4)) ); - break; + // // case "/": + // // value = Integer.parseInt( vars.get(options.get(2)) ) / Integer.parseInt( vars.get(options.get(4)) ); + // // break; - default: - tokenizer.close(); - return; + // // default: + // // return; - } - - vars.replace(options.get(0), String.valueOf(value)); + // // } - tokenizer.close(); - return; + // // //vars.replace(options.get(0), String.valueOf(value)); + + // // return; - } - else if ( windows.containsKey(options.get(0)) ) - { - switch(options.get(1)) - { - case "visible": - windows.get(options.get(0)).ToggleVisible(); - break; + // // } + // // else if ( windows.containsKey(options.get(0)) ) + // // { + // // switch(options.get(1)) + // // { + // // case "visible": + // // windows.get(options.get(0)).ToggleVisible(); + // // break; - case "title": - windows.get(options.get(0)).GetFrame().setTitle(GetRest(options, 2)); - break; + // // case "title": + // // windows.get(options.get(0)).GetFrame().setTitle(GetRest(options, 2)); + // // break; - default: - break; + // // default: + // // break; - } + // // } - } - else - JTerm.Parse(options); - - tokenizer.close(); - return; + // // } + // // else + + // return; - } - - tokenizer.close(); + // } - } + // } public static String GetRest(ArrayList options, int index) { @@ -289,4 +197,4 @@ public static String GetRest(ArrayList options, int index) } -} +} \ No newline at end of file diff --git a/src/main/java/jterm/Files.class b/src/main/java/jterm/Files.class deleted file mode 100644 index 340c157..0000000 Binary files a/src/main/java/jterm/Files.class and /dev/null differ diff --git a/src/main/java/jterm/Files.java b/src/main/java/jterm/Files.java index 5f016cc..55d756f 100644 --- a/src/main/java/jterm/Files.java +++ b/src/main/java/jterm/Files.java @@ -6,12 +6,10 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ @@ -21,8 +19,8 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileWriter; +import java.io.FileReader; import java.io.IOException; -import java.io.InputStreamReader; import java.util.ArrayList; public class Files @@ -32,6 +30,7 @@ public class Files * WriteFile() void * * Get input and write it to a file. + * Changelog (#65) * * ArrayList options - command options * @@ -52,15 +51,38 @@ public static void WriteFile(ArrayList options) } else - filename = JTerm.currentDirectory + option; + filename += option; + + } + + filename = filename.trim(); + filename = JTerm.currentDirectory + filename; + + if (filename.equals("")) + { + System.out.println("Error: missing filename; type \"write -h\" for more information."); + return; } try { - System.out.println("Enter file contents:\n"); - BufferedReader inputStream = new BufferedReader(new InputStreamReader(System.in), 1); - String output = inputStream.readLine(); + System.out.println("Enter file contents (press enter after a blank line to quit):"); + String line = JTerm.userInput.readLine(); + String output = line; + + for(;;) + { + line = JTerm.userInput.readLine(); + if (line.equals("")) + break; + + else if (line.equals(" ")) + output += "\n"; + + output += "\n" + line; + + } FileWriter fileWriter = new FileWriter(filename); fileWriter.write(output); @@ -99,13 +121,13 @@ public static void Delete(ArrayList options) } else - { - filename = JTerm.currentDirectory + option; - - } + filename += option; } + filename.trim(); + filename = JTerm.currentDirectory + filename; + File dir = new File(filename); if (!dir.exists()) { @@ -117,5 +139,60 @@ public static void Delete(ArrayList options) dir.delete(); } + + /* + * ReadFile() void + * Changelog (#68) + * + * Reads the specified files and outputs the contents + * to the console. + * + * ArrayList options - command options + * + * -h + * Prints help information + * + * Credit to @d4nntheman + */ + public static void ReadFile(ArrayList options) + { + + String filename = ""; + for (String option: options) + { + if (option.equals("-h")) + { + System.out.println("Command syntax:\n\t read [-h] [file1 file2 ...]\n\nReads and outputs the contents of the specified files."); + return; + + } + + filename = JTerm.currentDirectory + option; + File file = new File(filename); + if (!file.exists()) + { + System.out.println("ERROR: File/directory \"" + option + "\" does not exist."); + break; + + } + + try ( BufferedReader reader = new BufferedReader(new FileReader(file.getAbsolutePath())) ) + { + System.out.println("\n[JTerm - Contents of " + option + "]\n"); + String line = null; + while( (line = reader.readLine()) != null ) + System.out.println(line); + + } + catch (IOException e) + { + e.printStackTrace(); + return; + + } + + } + + } -} +} \ No newline at end of file diff --git a/src/main/java/jterm/JTerm.class b/src/main/java/jterm/JTerm.class deleted file mode 100644 index 3d13cac..0000000 Binary files a/src/main/java/jterm/JTerm.class and /dev/null differ diff --git a/src/main/java/jterm/JTerm.java b/src/main/java/jterm/JTerm.java index 73f903a..2dfdad4 100644 --- a/src/main/java/jterm/JTerm.java +++ b/src/main/java/jterm/JTerm.java @@ -6,12 +6,10 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ @@ -22,12 +20,13 @@ import java.util.Scanner; import java.io.*; import java.util.ArrayList; +import java.util.Hashtable; public class JTerm { // Global version variable - static String version = "0.4.0"; + static String version = "0.4.1"; // Global directory variable (use "cd" command to change) // Default value "./" is equal to the default directory set when the program starts @@ -35,6 +34,8 @@ public class JTerm static String commandChars = ""; + static Hashtable commands = new Hashtable(); + static BufferedReader userInput = new BufferedReader(new InputStreamReader(System.in)); /* @@ -68,7 +69,10 @@ public static void main(String[] args) quit = JTerm.Standby(); // As long as we are not quitting... - } while (!quit); + } while (!quit); + + // Close all open window instances + Window.CloseAll(); } @@ -199,6 +203,7 @@ public static boolean Parse(ArrayList options) break; case "read": + Files.ReadFile(options); break; /*case "connect": @@ -223,7 +228,39 @@ public static boolean Parse(ArrayList options) case "ping": Ping.PingHost(options); - break; + break; + + case "set": + Set.NewVar(options); + break; + + case "pause": + Pause.EnterPause(options); + break; + + // Commands to skip in batch files + case "bcdedit": + case "chkdsk": + case "chkntfs": + case "cls": + case "cmd": + case "color": + case "convert": + case "diskpart": + case "driverquery": + case "format": + case "fsutil": + case "gpresult": + case "mode": + case "sc": + case "shutdown": + case "start": + case "tasklist": + case "taskkill": + case "ver": + case "vol": + case "wmic": + break; default: // Create a new array that contains the command and check if it is an executable @@ -242,4 +279,4 @@ public static boolean Parse(ArrayList options) } -} +} \ No newline at end of file diff --git a/src/main/java/jterm/Pause.java b/src/main/java/jterm/Pause.java new file mode 100644 index 0000000..f6faa61 --- /dev/null +++ b/src/main/java/jterm/Pause.java @@ -0,0 +1,40 @@ +package main.java.jterm; + +import java.util.ArrayList; +import java.io.IOException; + +public class Pause +{ + + /* + * EnterPause() void + * + * Pauses the interpreter until the Enter + * key is hit. + * + * ArrayList options - command options + */ + public static void EnterPause(ArrayList options) + { + + if (options.size() == 1) + System.out.print("Press enter to continue..."); + + else + System.out.print(Exec.GetRest(options, 1)); + + try + { + JTerm.userInput.read(); + JTerm.userInput.skip(1); + + } + catch (IOException ioe) + { + System.out.println(ioe); + + } + + } + +} \ No newline at end of file diff --git a/src/main/java/jterm/Ps.java b/src/main/java/jterm/Ps.java index e53db1e..4211bbe 100644 --- a/src/main/java/jterm/Ps.java +++ b/src/main/java/jterm/Ps.java @@ -87,4 +87,4 @@ else if (SystemUtils.IS_OS_WINDOWS) } -} +} \ No newline at end of file diff --git a/src/main/java/jterm/Server$1.class b/src/main/java/jterm/Server$1.class deleted file mode 100644 index 2077598..0000000 Binary files a/src/main/java/jterm/Server$1.class and /dev/null differ diff --git a/src/main/java/jterm/Server.class b/src/main/java/jterm/Server.class deleted file mode 100644 index 53b60ea..0000000 Binary files a/src/main/java/jterm/Server.class and /dev/null differ diff --git a/src/main/java/jterm/Set.java b/src/main/java/jterm/Set.java new file mode 100644 index 0000000..5a35f76 --- /dev/null +++ b/src/main/java/jterm/Set.java @@ -0,0 +1,98 @@ +/* +* JTerm - a cross-platform terminal +* Copyright (C) 2017 Sergix, NCSGeek +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +package main.java.jterm; + +import java.util.Hashtable; +import java.util.Enumeration; +import java.util.ArrayList; + +public class Set +{ + + // Global variable hashtable + public static Hashtable vars = new Hashtable(); + + /* + * NewVar() void + * + * Creates a new variable that is stored in + * the global vars hashtable. + * + * ArrayList options - command options + */ + public static void NewVar(ArrayList options) + { + + // Print the value of all current variables + if (options.size() == 1) + { + PrintVars(); + return; + + } + + // Get the variable name + String key = options.get(1); + + // The name can't include spaces + if ( !options.get(2).equals("=") ) + return; + + // If the type is a window, create a new one + if (options.get(3).equals("window")) + { + // Remove the 'set' word from the options list + options.remove(0); + + // Pass the rest of the options to create a new Window + Window newWindow = new Window(options); + + // Put the window ID into the vars hashtable + // associated with its key + vars.put(key, Integer.toString(newWindow.GetId())); + + // Add the window to the global list + Window.windows.add(newWindow); + + return; + + } + + // Put the variable contents into the global hashtable + vars.put(key, Exec.GetRest(options, 3)); + + } + + /* + * PrintVars() void + * + * Prints the values of all variables + * currently stored. + */ + public static void PrintVars() + { + + String element = ""; + + // For each key... + for (Enumeration e = vars.keys(); e.hasMoreElements();) + // ...print in the format of "key=value" + System.out.println((element = e.nextElement()) + "=" + vars.get(element)); + + } + +} \ No newline at end of file diff --git a/src/main/java/jterm/Window.class b/src/main/java/jterm/Window.class deleted file mode 100644 index 0fc9f99..0000000 Binary files a/src/main/java/jterm/Window.class and /dev/null differ diff --git a/src/main/java/jterm/Window.java b/src/main/java/jterm/Window.java index 447f6ba..a00da78 100644 --- a/src/main/java/jterm/Window.java +++ b/src/main/java/jterm/Window.java @@ -25,6 +25,7 @@ public class Window { public static int windowCount = 0; + public static ArrayList windows = new ArrayList(); private int id; private JFrame window; @@ -118,8 +119,9 @@ else if(titleNext) window.setSize(width, height); window.setResizable(resizable); window.setVisible(visible); - + this.window = window; + windows.add(this); } @@ -130,6 +132,7 @@ else if(titleNext) */ public void ToggleVisible() { + window.setVisible(visible = !visible); } @@ -171,4 +174,16 @@ public String GetTitle() } + public static void CloseAll() + { + + for (Window window: windows) + { + window.GetFrame().setVisible(false); //you can't see me! + window.GetFrame().dispose(); //Destroy the JFrame object + + } + + } + } diff --git a/target/classes/main/java/jterm/Dir.class b/target/classes/main/java/jterm/Dir.class index 1012187..6f5be71 100644 Binary files a/target/classes/main/java/jterm/Dir.class and b/target/classes/main/java/jterm/Dir.class differ diff --git a/target/classes/main/java/jterm/Echo.class b/target/classes/main/java/jterm/Echo.class index cdb09e6..7e7ca88 100644 Binary files a/target/classes/main/java/jterm/Echo.class and b/target/classes/main/java/jterm/Echo.class differ diff --git a/target/classes/main/java/jterm/Exec.class b/target/classes/main/java/jterm/Exec.class index b6248e4..f45fd5d 100644 Binary files a/target/classes/main/java/jterm/Exec.class and b/target/classes/main/java/jterm/Exec.class differ diff --git a/target/classes/main/java/jterm/Files.class b/target/classes/main/java/jterm/Files.class index 446476d..9fd0d53 100644 Binary files a/target/classes/main/java/jterm/Files.class and b/target/classes/main/java/jterm/Files.class differ diff --git a/target/classes/main/java/jterm/Window.class b/target/classes/main/java/jterm/Window.class index 9aafa4e..bc7eb94 100644 Binary files a/target/classes/main/java/jterm/Window.class and b/target/classes/main/java/jterm/Window.class differ diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst deleted file mode 100644 index 2352f89..0000000 --- a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst +++ /dev/null @@ -1,11 +0,0 @@ -main\java\jterm\Server.class -main\java\jterm\Echo.class -main\java\jterm\Files.class -main\java\jterm\Exec.class -main\java\jterm\Window.class -main\java\jterm\Ps.class -main\java\jterm\Client.class -main\java\jterm\Server$1.class -main\java\jterm\Dir.class -main\java\jterm\JTerm.class -main\java\jterm\Ping.class diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst index 13d3c20..91b19b0 100644 --- a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -1,8 +1,12 @@ C:\Users\Sergi\Development\GitHub\JTerm\src\main\java\jterm\Window.java C:\Users\Sergi\Development\GitHub\JTerm\src\main\java\jterm\Echo.java +C:\Users\Sergi\Development\GitHub\JTerm\src\main\java\jterm\Pause.java C:\Users\Sergi\Development\GitHub\JTerm\src\main\java\jterm\Server.java C:\Users\Sergi\Development\GitHub\JTerm\src\main\java\jterm\Exec.java +C:\Users\Sergi\Development\GitHub\JTerm\src\main\java\jterm\Ping.java C:\Users\Sergi\Development\GitHub\JTerm\src\main\java\jterm\Client.java C:\Users\Sergi\Development\GitHub\JTerm\src\main\java\jterm\Files.java +C:\Users\Sergi\Development\GitHub\JTerm\src\main\java\jterm\Ps.java C:\Users\Sergi\Development\GitHub\JTerm\src\main\java\jterm\Dir.java C:\Users\Sergi\Development\GitHub\JTerm\src\main\java\jterm\JTerm.java +C:\Users\Sergi\Development\GitHub\JTerm\src\main\java\jterm\Set.java