From afd327f7b8a974fab0811ccc73ffc2174140d691 Mon Sep 17 00:00:00 2001 From: EverythingWindows Date: Mon, 7 Nov 2022 14:16:34 +0700 Subject: [PATCH] TextPad is finally working correctly --- .../MainForms/FileManagement.vb | 23 +- ShiftOS-TheRevival/MainForms/Terminal.vb | 345 ++++++++++++------ ShiftOS-TheRevival/MainForms/TerminalApps.vb | 124 ++++++- 3 files changed, 341 insertions(+), 151 deletions(-) diff --git a/ShiftOS-TheRevival/MainForms/FileManagement.vb b/ShiftOS-TheRevival/MainForms/FileManagement.vb index b4f6757..fcff2d6 100644 --- a/ShiftOS-TheRevival/MainForms/FileManagement.vb +++ b/ShiftOS-TheRevival/MainForms/FileManagement.vb @@ -3,18 +3,17 @@ Module FileManagement Public Sub CatFile(filename As String) If File.Exists(Terminal.CurrentDirectory & "\" & filename) = True Then - Try - Dim Contents As Byte() = File.ReadAllBytes(Terminal.CurrentDirectory & "\" & filename) - Dim ContentsFinal As String = Convert.ToString(Contents) - Terminal.TextBox1.Text = Terminal.TextBox1.Text & Environment.NewLine & ContentsFinal - Catch ex As Exception - Try - Dim ContentsFinal As String() = File.ReadAllLines(Terminal.CurrentDirectory & "\" & filename) - Terminal.TextBox1.Text = Terminal.TextBox1.Text & Environment.NewLine & ContentsFinal - Catch ex As Exception - - End Try - End Try + Dim ContentsFinal As String = File.ReadAllText(Terminal.CurrentDirectory & "\" & filename) + Terminal.TextBox1.Text = Terminal.TextBox1.Text & Environment.NewLine & ContentsFinal End If End Sub + + Public Sub SaveFile(filename As String) + 'If File.Exists(Terminal.CurrentDirectory & "\" & filename) = False Then + ' File.WriteAllText(Terminal.CurrentDirectory & "\" & filename, Terminal.TextBox1.Text) + 'Else + ' File.WriteAllText(Terminal.CurrentDirectory & "\" & filename, Terminal.TextBox1.Text) + 'End If + File.WriteAllText(Terminal.CurrentDirectory & "\" & filename, Terminal.TextBox1.Text) + End Sub End Module diff --git a/ShiftOS-TheRevival/MainForms/Terminal.vb b/ShiftOS-TheRevival/MainForms/Terminal.vb index 0c5565a..3d544e9 100644 --- a/ShiftOS-TheRevival/MainForms/Terminal.vb +++ b/ShiftOS-TheRevival/MainForms/Terminal.vb @@ -1,9 +1,9 @@ Imports System.IO Public Class Terminal + Public TrackPos As Integer Public command As String Public DefaultPrompt As String - Public TrackPos As Integer Public AdvancedCommand As Boolean Public BadCommand As Boolean Public DisplayStory As Integer @@ -266,11 +266,6 @@ Public Class Terminal TextBox1.Text = TextBox1.Text & Environment.NewLine AdvancedCommand = False BadCommand = False - Case "textpad" - ChangeInterpreter = True - AppHost("textpad", True) - AdvancedCommand = False - BadCommand = False Case "pwd" TextBox1.Text = TextBox1.Text & Environment.NewLine & CurrentDirectory.Replace(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\ShiftOS\ShiftFS", "!") AdvancedCommand = False @@ -365,12 +360,18 @@ Public Class Terminal If AdvancedCommand = True Then If command Like "cat *" Then - CatFile(command.Substring(4)) + If Strings.AvailableFeature(16) = 1 Then + CatFile(command.Substring(4)) + AdvancedCommand = False + BadCommand = False + End If End If If command Like "cd *" Then - NavigateDir(command.Replace("cd ", "")) - AdvancedCommand = False - BadCommand = False + If Strings.AvailableFeature(16) = 1 Then + NavigateDir(command.Replace("cd ", "")) + AdvancedCommand = False + BadCommand = False + End If End If If command Like "color *" Then GetColor("terminal", command.Substring(6, 1), command.Substring(7, 1)) @@ -481,14 +482,28 @@ Public Class Terminal End If End If If command Like "mkdir *" Then - CreateDir(command.Replace("mkdir ", "")) - AdvancedCommand = False - BadCommand = False + If Strings.AvailableFeature(16) Then + CreateDir(command.Replace("mkdir ", "")) + AdvancedCommand = False + BadCommand = False + End If + End If + If command Like "print *" Then + If Strings.AvailableFeature(2) = "1" Then + TextBox1.Text = TextBox1.Text & Environment.NewLine & command.Substring(6) + Dim printed As String = command.Replace("print ", "") + ''It has the same issue, only displays in lowercase + 'TextBox1.Text = TextBox1.Text & Environment.NewLine & printed + BadCommand = False + AdvancedCommand = False + End If End If If command Like "rmdir *" Then - RemoveDir(command.Replace("rmdir ", "")) - AdvancedCommand = False - BadCommand = False + If Strings.AvailableFeature(16) = 1 Then + RemoveDir(command.Replace("rmdir ", "")) + AdvancedCommand = False + BadCommand = False + End If End If If command Like "shiftorium *" Then Dim prompt As String = command.Replace("shiftorium ", "") @@ -506,16 +521,15 @@ Public Class Terminal BadCommand = False End If End If - If command Like "print *" Then - If Strings.AvailableFeature(2) = "1" Then - TextBox1.Text = TextBox1.Text & Environment.NewLine & command.Substring(6) - Dim printed As String = command.Replace("print ", "") - ''It has the same issue, only displays in lowercase - 'TextBox1.Text = TextBox1.Text & Environment.NewLine & printed + If command Like "textpad *" Then + If Strings.AvailableFeature(17) = 1 Then + ChangeInterpreter = True + command = command.Replace("textpad ", "") + AppHost("textpad", True) + AdvancedCommand = False BadCommand = False End If End If - AdvancedCommand = False End If If BadCommand = True Then @@ -523,124 +537,212 @@ Public Class Terminal End If End Sub + Public Sub TextRebind() + TextBox1.Select(TextBox1.Text.Length, 0) + TextBox1.ScrollToCaret() + End Sub + Private Sub txtterm_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown - - + TerminalApps.KeyInput = e.KeyData Select Case e.KeyData Case (Keys.Control + Keys.Q) If CurrentInterpreter = "terminal" Then Else - TerminateApp() - PrintPrompt() + TerminateApp(TerminalApps.KeyInput) + TextRebind() End If + Case Else + CaptureKeyBinding(TerminalApps.KeyInput) End Select - 'Select Case e.KeyCode - ' Case e.KeyCode = Keys.T AndAlso e.Control - ' e.SuppressKeyPress = True - ' Case e.KeyCode = Keys.Q AndAlso e.Control - ' If CurrentInterpreter = "terminal" Then + 'If ReleaseCursor = True Then + + 'Else + ' Select Case e.KeyCode + ' Case Keys.ShiftKey + ' TrackPos = TrackPos - 1 + ' Case Keys.Alt + ' TrackPos = TrackPos - 1 + ' Case Keys.CapsLock + ' TrackPos = TrackPos - 1 + ' Case Keys.ControlKey + ' TrackPos = TrackPos - 1 + ' Case Keys.LWin + ' TrackPos = TrackPos - 1 + ' Case Keys.RWin + ' TrackPos = TrackPos - 1 + ' Case Keys.Right + ' If TextBox1.SelectionStart = TextBox1.TextLength Then + ' TrackPos = TrackPos - 1 + ' End If + ' Case Keys.Left + ' If TrackPos < 1 Then + ' e.SuppressKeyPress = True + ' TrackPos = TrackPos - 1 + ' Else + ' TrackPos = TrackPos - 2 + ' End If + ' Case Keys.Up + ' e.SuppressKeyPress = True + ' TrackPos = TrackPos - 1 + ' Case Keys.Down + ' e.SuppressKeyPress = True + ' TrackPos = TrackPos - 1 + ' End Select + 'End If + + 'If e.KeyCode = Keys.Enter Then + ' e.SuppressKeyPress = True + ' If TextBox1.ReadOnly = True Then + + ' Else + ' ReadCommand() + ' If ChangeInterpreter = True Then + ' DoChildCommand() + ' PrintPrompt() + ' TextBox1.Select(TextBox1.Text.Length, 0) ' Else - ' TerminateApp() + ' DoCommand() + ' PrintPrompt() + ' TextBox1.Select(TextBox1.Text.Length, 0) ' End If - 'End Select + ' End If + + ' 'If command = "clear" Then + ' ' PrintPrompt() + ' ' TextBox1.Select(TextBox1.Text.Length, 0) + + ' 'Else + ' ' PrintPrompt() + ' ' TextBox1.Select(TextBox1.Text.Length, 0) + ' 'End If + + ' TrackPos = 0 + 'Else + ' If ReleaseCursor = True Then + + ' Else + ' If e.KeyCode = Keys.Back Then + ' Else + ' TrackPos = TrackPos + 1 + ' End If + ' End If + 'End If + + 'If e.KeyCode = Keys.Back Then + ' If TrackPos < 1 Then + ' e.SuppressKeyPress = True + ' Else + ' If TextBox1.SelectedText.Length < 1 Then + ' TrackPos = TrackPos - 1 + ' Else + ' e.SuppressKeyPress = True + ' End If + ' End If + 'End If + 'TextBox1.Select(TextBox1.TextLength, 0) + 'TextBox1.ScrollToCaret() If ReleaseCursor = True Then Else - If ReleaseCursor = True Then + Select Case e.KeyData + Case Keys.Enter + e.SuppressKeyPress = True + If TextBox1.ReadOnly = True Then - Else - Select Case e.KeyCode - Case Keys.ShiftKey - TrackPos = TrackPos - 1 - Case Keys.Alt - TrackPos = TrackPos - 1 - Case Keys.CapsLock - TrackPos = TrackPos - 1 - Case Keys.ControlKey - TrackPos = TrackPos - 1 - Case Keys.Right - If TextBox1.SelectionStart = TextBox1.TextLength Then - TrackPos = TrackPos - 1 - End If - Case Keys.Left - If TrackPos < 1 Then - e.SuppressKeyPress = True - TrackPos = TrackPos - 1 - Else - TrackPos = TrackPos - 2 - End If - Case Keys.Up - e.SuppressKeyPress = True - TrackPos = TrackPos - 1 - Case Keys.Down - e.SuppressKeyPress = True - TrackPos = TrackPos - 1 - End Select - End If - Select Case e.KeyCode - Case Keys.LWin - TrackPos = TrackPos - 1 - Case Keys.RWin - TrackPos = TrackPos - 1 - End Select - - If e.KeyCode = Keys.Enter Then - e.SuppressKeyPress = True - If TextBox1.ReadOnly = True Then - - Else - ReadCommand() - If ChangeInterpreter = True Then - DoChildCommand() - PrintPrompt() - TextBox1.Select(TextBox1.Text.Length, 0) Else - DoCommand() - PrintPrompt() - TextBox1.Select(TextBox1.Text.Length, 0) + ReadCommand() + If ChangeInterpreter = True Then + DoChildCommand() + PrintPrompt() + TextRebind() + Else + DoCommand() + PrintPrompt() + TextRebind() + End If End If - End If - - 'If command = "clear" Then - ' PrintPrompt() - ' TextBox1.Select(TextBox1.Text.Length, 0) - - 'Else - ' PrintPrompt() - ' TextBox1.Select(TextBox1.Text.Length, 0) - 'End If - - TrackPos = 0 - Else - If ReleaseCursor = True Then - - Else - If e.KeyCode = Keys.Back Then + TrackPos = 0 + Case Keys.ShiftKey, Keys.Alt, Keys.ControlKey, Keys.LWin, Keys.RWin + e.SuppressKeyPress = True + Case Keys.Back + If TrackPos <= 0 Then + e.SuppressKeyPress = True + Else + TrackPos = TrackPos - 1 + 'If TextBox1.SelectedText.Length < 1 Then + ' TrackPos = TrackPos - 1 + 'Else + ' e.SuppressKeyPress = True + 'End If + End If + Case Keys.Right + If TextBox1.SelectionStart = TextBox1.TextLength Then Else TrackPos = TrackPos + 1 End If - End If - End If - - If ReleaseCursor = True Then - - Else - If e.KeyCode = Keys.Back Then - If TrackPos < 1 Then + 'If TrackPos <= 0 Then + ' Dim CommandChar As String + ' CommandChar = TextBox1.Lines(TextBox1.Lines.Length - 1) + ' CommandChar = CommandChar.Replace(DefaultPrompt, "") + ' TrackPos = CommandChar.Length - 1 + ' TextBox1.Select(TextBox1.TextLength, 0) + ' TextBox1.ScrollToCaret() + 'End If + Case Keys.Left + If TextBox1.SelectionStart = 0 Then e.SuppressKeyPress = True Else - If TextBox1.SelectedText.Length < 1 Then - TrackPos = TrackPos - 1 - Else - e.SuppressKeyPress = True - End If + TrackPos = TrackPos - 1 End If - End If - End If - + If TrackPos <= 0 Then + Dim CommandChar As String + CommandChar = TextBox1.Lines(TextBox1.Lines.Length - 1) + CommandChar = CommandChar.Replace(DefaultPrompt, "") + TrackPos = CommandChar.Length - 1 + TextBox1.Select(TextBox1.TextLength, 0) + TextBox1.ScrollToCaret() + End If + 'If TrackPos < 1 Then + ' e.SuppressKeyPress = True + ' TrackPos = TrackPos - 1 + 'Else + ' TrackPos = TrackPos - 2 + 'End If + Case Keys.Up + e.SuppressKeyPress = True + Case Keys.Down + e.SuppressKeyPress = True + Case Else + TrackPos = TrackPos + 1 + End Select End If - TextBox1.Select(TextBox1.TextLength, 0) - TextBox1.ScrollToCaret() + 'If e.KeyCode = Keys.Enter Then + ' 'If command = "clear" Then + ' ' txtterm.Text = txtterm.Text + ShiftOSDesktop.username & "@" & ShiftOSDesktop.osname & " $> " + ' ' txtterm.Select(txtterm.Text.Length, 0) + + ' 'Else + ' ' txtterm.Text = txtterm.Text + Environment.NewLine & ShiftOSDesktop.username & "@" & ShiftOSDesktop.osname & " $> " + ' ' txtterm.Select(txtterm.Text.Length, 0) + ' 'End If + 'Else + ' If e.KeyCode = Keys.Back Then + ' Else + ' TrackPos = TrackPos + 1 + ' End If + 'End If + + 'If e.KeyCode = Keys.Back Then + ' 'If TrackPos < 1 Then + ' ' e.SuppressKeyPress = True + ' 'Else + ' ' If TextBox1.SelectedText.Length < 1 Then + ' ' TrackPos = TrackPos - 1 + ' ' Else + ' ' e.SuppressKeyPress = True + ' ' End If + ' 'End If + 'End If End Sub Private Sub TextBox1_Click(sender As Object, e As EventArgs) Handles TextBox1.Click, TextBox1.MouseDoubleClick @@ -718,5 +820,10 @@ Public Class Terminal End If InfoBar.Text = InfoBar.Text & " " & CurrentInterpreter & " |" InfoBar.Text = InfoBar.Text & " " & Strings.ComputerInfo(2) & " CP |" + InfoBar.Text = InfoBar.Text & " " & TrackPos & " |" + End Sub + + Private Sub TextBox1_Click(sender As Object, e As MouseEventArgs) Handles TextBox1.MouseDoubleClick, TextBox1.Click + End Sub End Class \ No newline at end of file diff --git a/ShiftOS-TheRevival/MainForms/TerminalApps.vb b/ShiftOS-TheRevival/MainForms/TerminalApps.vb index 7c5a4a4..158fb8f 100644 --- a/ShiftOS-TheRevival/MainForms/TerminalApps.vb +++ b/ShiftOS-TheRevival/MainForms/TerminalApps.vb @@ -1,5 +1,8 @@ -Module TerminalApps +Imports System.IO + +Module TerminalApps Public ShouldChange As Boolean = False + Public KeyInput As Keys 'This is for GTN's RAM Public TheNumber As Integer = 0 Public FreezeText As String @@ -12,6 +15,9 @@ Public BC_CurrentNumber As String Public BC_Result As Integer Public BC_Operation2 As String + 'TextPad's RAM + Public TextPad_FileName As String + Public TextPad_TempText As New Timer Public Sub ChangeCP(Addition As Boolean, NeededCP As Integer) Dim TempCP As Integer = Convert.ToInt32(Strings.ComputerInfo(2)) @@ -50,17 +56,18 @@ Terminal.TextBox1.Text = Terminal.TextBox1.Text & Environment.NewLine & Environment.NewLine & "Type any package you want to investigate" ShouldChange = True Case "textpad" - Terminal.DefaultPrompt = "" + Terminal.DefaultPrompt = Nothing + Terminal.TextBox1.Text = Nothing Terminal.ToolBarUse = True Terminal.CheckFeature() Terminal.CurrentInterpreter = "textpad" - Terminal.ToolBar.Text = "TextPad - " & Environment.NewLine & "Ctrl-Q Exit | Ctrl-N New | Ctrl-O Open | Ctrl-S Save | F12 Save As" - Terminal.TextBox1.Text = Nothing + TextPad_CheckExist(Terminal.command) + Terminal.ToolBar.Text = "TextPad - " & Terminal.command & Environment.NewLine & "Ctrl-Q Exit | Ctrl-N New | Ctrl-O Open | Ctrl-S Save | F12 Save As" Terminal.ReleaseCursor = True End Select If Terminal.ReleaseCursor = True Then - Strings.OnceInfo(5) = Terminal.TrackPos - Terminal.TrackPos = Nothing + 'Strings.OnceInfo(5) = Terminal.TrackPos + 'Terminal.TrackPos = Nothing End If If ShouldChange = True Then Terminal.ChangeInterpreter = True @@ -68,17 +75,67 @@ End If End Sub - Public Sub TerminateApp() - If Terminal.ReleaseCursor = True Then - Terminal.TrackPos = Strings.OnceInfo(5) - Strings.OnceInfo(5) = 0 - End If - Terminal.ToolBarUse = False - Terminal.ChangeInterpreter = False - Terminal.ReleaseCursor = False - Terminal.CurrentInterpreter = "terminal" - Terminal.CheckFeature() - Terminal.AssignPrompt() + Public Sub CaptureKeyBinding(KeysInput As Keys) + Select Case KeysInput + Case (Keys.S + Keys.Control) + If File.Exists(Terminal.CurrentDirectory & "\" & Terminal.command) = True Then + Dim TempCompare As String = File.ReadAllText(Terminal.CurrentDirectory & "\" & Terminal.command) + If Terminal.TextBox1.Text = TempCompare Then + + Else + Dim BeforeCP As Integer = Strings.ComputerInfo(2) + SaveFile(Terminal.command) + TextPad_GenerateCP_SavedFile() + Dim AfterCP As Integer = Strings.ComputerInfo(2) - BeforeCP + Terminal.ToolBar.Text = "TextPad - " & Terminal.command & " - You've got " & AfterCP & " Codepoints" & Environment.NewLine & "Ctrl-Q Exit | Ctrl-N New | Ctrl-O Open | Ctrl-S Save | F12 Save As" + End If + Else + Dim BeforeCP As Integer = Strings.ComputerInfo(2) + SaveFile(Terminal.command) + TextPad_GenerateCP_SavedFile() + Dim AfterCP As Integer = Strings.ComputerInfo(2) - BeforeCP + Terminal.ToolBar.Text = "TextPad - " & Terminal.command & " - You've got " & AfterCP & " Codepoints" & Environment.NewLine & "Ctrl-Q Exit | Ctrl-N New | Ctrl-O Open | Ctrl-S Save | F12 Save As" + End If + End Select + End Sub + + Public Sub TerminateApp(KeyInput As Keys) + Select Case Terminal.CurrentInterpreter + Case "textpad" + Dim BeforeCP As Integer = Strings.ComputerInfo(2) + If File.Exists(Terminal.CurrentDirectory & "\" & Terminal.command) = True Then + Dim TextCompare As String = My.Computer.FileSystem.ReadAllText(Terminal.CurrentDirectory & "\" & Terminal.command) + If Terminal.TextBox1.Text = TextCompare Then + Terminal.TextBox1.Text = Nothing + Else + SaveFile(Terminal.command) + TextPad_GenerateCP_SavedFile() + Dim AfterCP As Integer = Strings.ComputerInfo(2) - BeforeCP + Terminal.TextBox1.Text = "You've got " & AfterCP & " Codepoints" + End If + Else + SaveFile(Terminal.command) + TextPad_GenerateCP_SavedFile() + Dim AfterCP As Integer = Strings.ComputerInfo(2) - BeforeCP + Terminal.TextBox1.Text = "You've got " & AfterCP & " Codepoints" + End If + Terminal.ToolBarUse = False + Terminal.ChangeInterpreter = False + Terminal.ReleaseCursor = False + Terminal.CurrentInterpreter = "terminal" + Terminal.CheckFeature() + Terminal.AssignPrompt() + Terminal.PrintPrompt() + Terminal.TextRebind() + Case Else + Terminal.ToolBarUse = False + Terminal.ChangeInterpreter = False + Terminal.ReleaseCursor = False + Terminal.CurrentInterpreter = "terminal" + Terminal.CheckFeature() + Terminal.AssignPrompt() + Terminal.TextRebind() + End Select End Sub Public Sub DoChildCommand() @@ -86,7 +143,7 @@ Case "guess" Select Case Terminal.command Case "exit" - TerminateApp() + TerminateApp(Nothing) Case Else Try GTN_CheckNumber() @@ -99,7 +156,7 @@ Case "" Case "exit" - TerminateApp() + TerminateApp(Nothing) Case Else ShiftoriumFX_DisplayPackages() Terminal.TextBox1.Text = Terminal.TextBox1.Text & Environment.NewLine & Environment.NewLine & "Type any package you want to investigate" & Environment.NewLine & "Invalid package or bad command" @@ -111,7 +168,7 @@ Case "ojas" Terminal.TextBox1.Text = Terminal.TextBox1.Text & Environment.NewLine & "dis calculator is very gud" & Environment.NewLine & "it counts from another universe" Case "exit" - TerminateApp() + TerminateApp(Nothing) Case Else BC_ReadNumbers = 0 BC_ThriceMoreValue = 1 @@ -200,6 +257,33 @@ End If End Sub + Public Sub TextPad_CheckExist(TxtFileName As String) + If File.Exists(Terminal.CurrentDirectory & "\" & TxtFileName) = True Then + Terminal.TextBox1.Text = My.Computer.FileSystem.ReadAllText(Terminal.CurrentDirectory & "\" & TxtFileName) + End If + End Sub + + Public Sub TextPad_GenerateCP_SavedFile() + Select Case Terminal.TextBox1.TextLength + Case 1 To 9 + Dim GetCP As New Random + Dim GotCP As Integer = GetCP.Next(1, 6) + ChangeCP(True, GotCP) + Case 10 To 99 + Dim GetCP As New Random + Dim GotCP As Integer = GetCP.Next(1, 51) + ChangeCP(True, GotCP) + Case 100 To 999 + Dim GetCP As New Random + Dim GotCP As Integer = GetCP.Next(1, 501) + ChangeCP(True, GotCP) + Case 1000 To 9999 + Dim GetCP As New Random + Dim GotCP As Integer = GetCP.Next(1, 5001) + ChangeCP(True, GotCP) + End Select + End Sub + Public Sub ShiftoriumFX_DisplayPackages() Terminal.TextBox1.Text = "Shiftorium FX!" & Environment.NewLine & "The place to shiftisize the ShiftOS" & Environment.NewLine & Environment.NewLine & "Available Package(s)" Shiftorium_ListFeatures()