| 1 |
#Region "Microsoft.VisualBasic::12826d208ac41a93beab4e252c673311, Microsoft.VisualBasic.Core\ApplicationServices\Terminal\InteractiveIODevice\HistoryStacks.vb"
|
| 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 |
#End Region
|
| 54 |
|
| 55 |
Imports System.Xml.Serialization
|
| 56 |
Imports Microsoft.VisualBasic.ComponentModel
|
| 57 |
Imports Microsoft.VisualBasic.Serialization.JSON
|
| 58 |
|
| 59 |
Namespace Terminal
|
| 60 |
|
| 61 |
Public Class HistoryStacks : Inherits ITextFile
|
| 62 |
Implements ISaveHandle
|
| 63 |
|
| 64 |
Dim _historyList As List(Of String)
|
| 65 |
Dim _lsthistory As List(Of History)
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
Dim p As Integer
|
| 72 |
|
| 73 |
Public Property HistoryList As List(Of History)
|
| 74 |
Get
|
| 75 |
Return _lsthistory
|
| 76 |
End Get
|
| 77 |
Set(value As List(Of History))
|
| 78 |
_lsthistory = value
|
| 79 |
End Set
|
| 80 |
End Property
|
| 81 |
|
| 82 |
Dim LastHistory As History
|
| 83 |
|
| 84 |
Sub New()
|
| 85 |
LastHistory = New History With {
|
| 86 |
.Date = Now.ToString,
|
| 87 |
.Histories = New List(Of String)
|
| 88 |
}
|
| 89 |
End Sub
|
| 90 |
|
| 91 |
Sub New(path As String)
|
| 92 |
Call Me.New
|
| 93 |
FilePath = path
|
| 94 |
End Sub
|
| 95 |
|
| 96 |
Public Sub StartInitialize()
|
| 97 |
Call __init()
|
| 98 |
_historyList = (From his As History In _lsthistory Select his.Histories).Unlist
|
| 99 |
p = _historyList.Count - 1
|
| 100 |
If p < 0 Then p = 0
|
| 101 |
End Sub
|
| 102 |
|
| 103 |
Public Sub PushStack(s As String)
|
| 104 |
If _historyList.IsNullOrEmpty Then
|
| 105 |
Call __init()
|
| 106 |
End If
|
| 107 |
|
| 108 |
Call LastHistory.Histories.Add(s)
|
| 109 |
Call _historyList.Insert(p, s)
|
| 110 |
End Sub
|
| 111 |
|
| 112 |
Private Sub __init()
|
| 113 |
_historyList = New List(Of String)
|
| 114 |
If _lsthistory.IsNullOrEmpty Then _lsthistory = New List(Of History)
|
| 115 |
Call _lsthistory.Add(LastHistory)
|
| 116 |
End Sub
|
| 117 |
|
| 118 |
Public Function MovePrevious() As String
|
| 119 |
p -= 1
|
| 120 |
Return __getHistory()
|
| 121 |
End Function
|
| 122 |
|
| 123 |
Public Function MoveNext() As String
|
| 124 |
p += 1
|
| 125 |
Return __getHistory()
|
| 126 |
End Function
|
| 127 |
|
| 128 |
Public Function MoveFirst() As String
|
| 129 |
p = 0
|
| 130 |
Return __getHistory()
|
| 131 |
End Function
|
| 132 |
|
| 133 |
Public Function MoveLast() As String
|
| 134 |
p = _historyList.Count - 1
|
| 135 |
Return __getHistory()
|
| 136 |
End Function
|
| 137 |
|
| 138 |
Private Function __getHistory() As String
|
| 139 |
If p < 0 Then
|
| 140 |
p = 0
|
| 141 |
End If
|
| 142 |
|
| 143 |
If _historyList.IsNullOrEmpty Then
|
| 144 |
Call __init()
|
| 145 |
Return ""
|
| 146 |
End If
|
| 147 |
|
| 148 |
If p > _historyList.Count - 1 Then
|
| 149 |
p = _historyList.Count - 1
|
| 150 |
End If
|
| 151 |
|
| 152 |
Dim s As String = _historyList(p)
|
| 153 |
Return s
|
| 154 |
End Function
|
| 155 |
|
| 156 |
Public Structure History
|
| 157 |
|
| 158 |
Public [Date] As String
|
| 159 |
Public Histories As List(Of String)
|
| 160 |
|
| 161 |
Public Overrides Function ToString() As String
|
| 162 |
Return Me.GetJson
|
| 163 |
End Function
|
| 164 |
End Structure
|
| 165 |
|
| 166 |
Public Overrides Function ToString() As String
|
| 167 |
Return String.Join("; ", _historyList.Take(3).ToArray) & "......."
|
| 168 |
End Function
|
| 169 |
|
| 170 |
Public Overrides Function Save(Optional Path As String = "", Optional encoding As System.Text.Encoding = Nothing) As Boolean
|
| 171 |
Path = MyBase.getPath(Path)
|
| 172 |
Return Me.GetXml.SaveTo(Path, encoding)
|
| 173 |
End Function
|
| 174 |
|
| 175 |
Protected Overrides Function __getDefaultPath() As String
|
| 176 |
Return FilePath
|
| 177 |
End Function
|
| 178 |
End Class
|
| 179 |
End Namespace
|