-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindow2.xaml.cs
More file actions
120 lines (101 loc) · 3.37 KB
/
Window2.xaml.cs
File metadata and controls
120 lines (101 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
using System;
using System.IO;
using System.Windows;
namespace OpenStudioIDE
{
public partial class Window2 : Window
{
public Window2()//shell
{
InitializeComponent();
Welcome();
}
private void Welcome()
{
PrintToOutput("Welcome to the PythonicOS shell designed for the OpenStudioIDE!");
PrintToOutput("To get started just type 'help' and then press enter!");
}
private void InputTextBox_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
{
if (e.Key == System.Windows.Input.Key.Enter)
{
ProcessInput(InputTextBox.Text);
InputTextBox.Clear();
}
}
private void ProcessInput(string input)
{
PrintToOutput($"> {input}");
var command = input.Split(' ')[0].ToLower();
switch (command)
{
case "cd":
ChangeDirectory(input);
break;
case "help":
Help();
break;
case "ls":
ListDirectory(input);
break;
case "exit":
Close();
break;
default:
PrintToOutput("Invalid command");
break;
}
}
private void PrintToOutput(string text)
{
OutputTextBox.AppendText(text + Environment.NewLine);
OutputTextBox.ScrollToEnd();
}
private void Help()
{
PrintToOutput("cd: changes directory");
PrintToOutput("ls: list files in directory");
PrintToOutput("run: runs 'dotnet run' on your computer in the local folder that the shell is in");
}
private void ChangeDirectory(string input)
{
var arguments = input.Split(' ')[1];
try
{
Directory.SetCurrentDirectory(arguments);
}
catch (Exception e)
{
PrintToOutput($"Error changing directory: {e.Message}");
}
}
private void ListDirectory(string input)
{
var arguments = input.Split(' ').Length > 1 ? input.Split(' ')[1] : string.Empty;
var directory = string.IsNullOrEmpty(arguments) ? Directory.GetCurrentDirectory() : arguments;
try
{
var files = Directory.GetFiles(directory);
var directories = Directory.GetDirectories(directory);
PrintToOutput("Files:");
foreach (var file in files)
{
PrintToOutput(file);
}
PrintToOutput("Directories:");
foreach (var dir in directories)
{
PrintToOutput(dir);
}
}
catch (Exception e)
{
PrintToOutput($"Error listing directory: {e.Message}");
}
}
private void MenuItem_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("woops? seems like this aint implemented yet, just goahead and close the window by pressing the x on the right of the window at the top! cheers!");
}
}
}