summaryrefslogtreecommitdiff
path: root/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c')
-rw-r--r--ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c329
1 files changed, 303 insertions, 26 deletions
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
index acd8512ff3..fb0c76e2e9 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
@@ -1,7 +1,7 @@
/** @file
Implements filebuffer interface functions.
- Copyright (c) 2005 - 2015, Intel Corporation. All rights reserved. <BR>
+ Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved. <BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -257,6 +257,71 @@ MoveLine (
}
/**
+ Decide if a point is in the already selected area.
+
+ @param[in] MouseRow The row of the point to test.
+ @param[in] MouseCol The col of the point to test.
+
+ @retval TRUE The point is in the selected area.
+ @retval FALSE The point is not in the selected area.
+**/
+BOOLEAN
+FileBufferIsInSelectedArea (
+ IN UINTN MouseRow,
+ IN UINTN MouseCol
+ )
+{
+ UINTN FRow;
+ UINTN RowStart;
+ UINTN RowEnd;
+ UINTN ColStart;
+ UINTN ColEnd;
+ UINTN MouseColStart;
+ UINTN MouseColEnd;
+
+ //
+ // judge mouse position whether is in selected area
+ //
+ //
+ // not select
+ //
+ if (MainEditor.SelectStart == 0 || MainEditor.SelectEnd == 0) {
+ return FALSE;
+ }
+ //
+ // calculate the select area
+ //
+ RowStart = (MainEditor.SelectStart - 1) / SHELL_EDIT_MAX_LINE_SIZE + 1;
+ RowEnd = (MainEditor.SelectEnd - 1) / SHELL_EDIT_MAX_LINE_SIZE + 1;
+
+ ColStart = (MainEditor.SelectStart - 1) % SHELL_EDIT_MAX_LINE_SIZE + 1;
+ ColEnd = (MainEditor.SelectEnd - 1) % SHELL_EDIT_MAX_LINE_SIZE + 1;
+
+ FRow = FileBuffer.LowVisibleRange.Row + MouseRow - 2;
+ if (FRow < RowStart || FRow > RowEnd) {
+ return FALSE;
+ }
+
+ if (FRow > RowStart) {
+ ColStart = 1;
+ }
+
+ if (FRow < RowEnd) {
+ ColEnd = SHELL_EDIT_MAX_LINE_SIZE;
+ }
+
+ MouseColStart = ColStart;
+
+ MouseColEnd = ColEnd;
+
+ if (MouseCol < MouseColStart || MouseCol > MouseColEnd) {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/**
Function to update the 'screen' to display the mouse position.
@retval EFI_SUCCESS The backup operation was successful.
@@ -311,6 +376,29 @@ FileBufferRestoreMousePosition (
FColumn = FileBuffer.LowVisibleRange.Column + FileBufferBackupVar.MousePosition.Column - 1;
+ if (FRow <= FileBuffer.NumLines) {
+ CurrentLine = FileBuffer.CurrentLine;
+ Line = MoveLine (FRow - FileBuffer.FilePosition.Row);
+ FileBuffer.CurrentLine = CurrentLine;
+ }
+
+ //
+ // if in selected area,
+ // so do not need to refresh mouse
+ //
+ if (!FileBufferIsInSelectedArea (
+ FileBufferBackupVar.MousePosition.Row,
+ FileBufferBackupVar.MousePosition.Column
+ ) ||
+ (Line == NULL || FColumn > Line->Size)
+ ) {
+ gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);
+ } else {
+ gST->ConOut->SetAttribute (gST->ConOut, New.Data & 0x7F);
+ }
+
+ Line = NULL;
+
HasCharacter = TRUE;
if (FRow > FileBuffer.NumLines) {
HasCharacter = FALSE;
@@ -343,8 +431,15 @@ FileBufferRestoreMousePosition (
//
// set the new mouse position
//
- gST->ConOut->SetAttribute (gST->ConOut, New.Data & 0x7F);
-
+ if (!FileBufferIsInSelectedArea (
+ FileBuffer.MousePosition.Row,
+ FileBuffer.MousePosition.Column
+ )
+ ) {
+ gST->ConOut->SetAttribute (gST->ConOut, New.Data & 0x7F);
+ } else {
+ gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);
+ }
//
// clear the old mouse position
//
@@ -472,18 +567,25 @@ FileBufferCleanup (
}
+
/**
- Print a line specified by Line on a row specified by Row of the screen.
+ Print Line on Row
- @param[in] Line The line to print.
- @param[in] Row The row on the screen to print onto (begin from 1).
+ @param[in] Line The lline to print.
+ @param[in] Row The row on screen ( begin from 1 ).
+ @param[in] FRow The FRow.
+ @param[in] Orig The original color.
+ @param[in] New The color to print with.
- @retval EFI_SUCCESS The printing was successful.
+ @retval EFI_SUCCESS The operation was successful.
**/
EFI_STATUS
FileBufferPrintLine (
- IN CONST EFI_EDITOR_LINE *Line,
- IN CONST UINTN Row
+ IN CONST EFI_EDITOR_LINE *Line,
+ IN CONST UINTN Row,
+ IN CONST UINTN FRow,
+ IN EFI_EDITOR_COLOR_UNION Orig,
+ IN EFI_EDITOR_COLOR_UNION New
)
{
@@ -491,7 +593,42 @@ FileBufferPrintLine (
UINTN Limit;
CHAR16 *PrintLine;
CHAR16 *PrintLine2;
- UINTN BufLen;
+ CHAR16 *TempString;
+ UINTN BufLen;
+ BOOLEAN Selected;
+ UINTN RowStart;
+ UINTN RowEnd;
+ UINTN ColStart;
+ UINTN ColEnd;
+
+ ColStart = 0;
+ ColEnd = 0;
+ Selected = FALSE;
+ TempString = NULL;
+
+ //
+ // print the selected area in opposite color
+ //
+ if (MainEditor.SelectStart != 0 && MainEditor.SelectEnd != 0) {
+ RowStart = (MainEditor.SelectStart - 1) / SHELL_EDIT_MAX_LINE_SIZE + 1;
+ RowEnd = (MainEditor.SelectEnd - 1) / SHELL_EDIT_MAX_LINE_SIZE + 1;
+
+ ColStart = (MainEditor.SelectStart - 1) % SHELL_EDIT_MAX_LINE_SIZE + 1;
+ ColEnd = (MainEditor.SelectEnd - 1) % SHELL_EDIT_MAX_LINE_SIZE + 1;
+
+ if (FRow >= RowStart && FRow <= RowEnd) {
+ Selected = TRUE;
+ }
+
+ if (FRow > RowStart) {
+ ColStart = 1;
+ }
+
+ if (FRow < RowEnd) {
+ ColEnd = Line->Size + 1;
+ }
+
+ }
//
// print start from correct character
@@ -519,15 +656,64 @@ FileBufferPrintLine (
ShellCopySearchAndReplace(PrintLine, PrintLine2, BufLen * 2, L"%", L"^%", FALSE, FALSE);
- ShellPrintEx (
- 0,
- (INT32)Row - 1,
- L"%s",
- PrintLine2
- );
+ if (!Selected) {
+ ShellPrintEx (
+ 0,
+ (INT32)Row - 1,
+ L"%s",
+ PrintLine2
+ );
+ } else {
+ //
+ // If the current line is selected.
+ //
+ if (ColStart != 1) {
+ gST->ConOut->SetAttribute (gST->ConOut, Orig.Data & 0x7F);
+ TempString = AllocateCopyPool ((ColStart - 1) * sizeof(CHAR16), PrintLine2);
+ ASSERT (TempString != NULL);
+ ShellPrintEx (
+ 0,
+ (INT32)Row - 1,
+ L"%s",
+ TempString
+ );
+ FreePool (TempString);
+ }
+
+ gST->ConOut->SetAttribute (gST->ConOut, New.Data & 0x7F);
+ TempString = AllocateCopyPool (
+ (ColEnd - ColStart + 1) * sizeof(CHAR16),
+ PrintLine2 + ColStart - 1
+ );
+ ASSERT (TempString != NULL);
+ ShellPrintEx (
+ (INT32)ColStart - 1,
+ (INT32)Row - 1,
+ L"%s",
+ TempString
+ );
+ FreePool (TempString);
+
+ if (ColEnd != SHELL_EDIT_MAX_LINE_SIZE) {
+ gST->ConOut->SetAttribute (gST->ConOut, Orig.Data & 0x7F);
+ TempString = AllocateCopyPool (
+ (SHELL_EDIT_MAX_LINE_SIZE - ColEnd + 1) * sizeof(CHAR16),
+ PrintLine2 + ColEnd - 1
+ );
+ ASSERT (TempString != NULL);
+ ShellPrintEx (
+ (INT32)ColEnd - 1,
+ (INT32)Row - 1,
+ L"%s",
+ TempString
+ );
+ FreePool (TempString);
+ }
+ }
FreePool (PrintLine);
FreePool (PrintLine2);
+ gST->ConOut->SetAttribute (gST->ConOut, Orig.Data & 0x7F);
return EFI_SUCCESS;
}
@@ -568,6 +754,18 @@ FileBufferRefresh (
LIST_ENTRY *Link;
EFI_EDITOR_LINE *Line;
UINTN Row;
+ EFI_EDITOR_COLOR_UNION Orig;
+ EFI_EDITOR_COLOR_UNION New;
+
+ UINTN StartRow;
+ UINTN EndRow;
+ UINTN FStartRow;
+ UINTN Tmp;
+
+ Orig = MainEditor.ColorAttributes;
+ New.Data = 0;
+ New.Colors.Foreground = Orig.Colors.Background;
+ New.Colors.Background = Orig.Colors.Foreground;
//
// if it's the first time after editor launch, so should refresh
@@ -579,13 +777,10 @@ FileBufferRefresh (
//
if (!FileBufferNeedRefresh &&
!FileBufferOnlyLineNeedRefresh &&
- FileBufferBackupVar.LowVisibleRange.Row == FileBuffer.LowVisibleRange.Row &&
- FileBufferBackupVar.LowVisibleRange.Column == FileBuffer.LowVisibleRange.Column
+ FileBufferBackupVar.LowVisibleRange.Row == FileBuffer.LowVisibleRange.Row
) {
-
FileBufferRestoreMousePosition ();
FileBufferRestorePosition ();
-
return EFI_SUCCESS;
}
}
@@ -596,19 +791,60 @@ FileBufferRefresh (
// only need to refresh current line
//
if (FileBufferOnlyLineNeedRefresh &&
- FileBufferBackupVar.LowVisibleRange.Row == FileBuffer.LowVisibleRange.Row &&
- FileBufferBackupVar.LowVisibleRange.Column == FileBuffer.LowVisibleRange.Column
+ FileBufferBackupVar.LowVisibleRange.Row == FileBuffer.LowVisibleRange.Row
) {
EditorClearLine (FileBuffer.DisplayPosition.Row, MainEditor.ScreenSize.Column, MainEditor.ScreenSize.Row);
FileBufferPrintLine (
FileBuffer.CurrentLine,
- FileBuffer.DisplayPosition.Row
+ FileBuffer.DisplayPosition.Row,
+ FileBuffer.FilePosition.Row,
+ Orig,
+ New
);
} else {
//
// the whole edit area need refresh
//
+ if (EditorMouseAction && MainEditor.SelectStart != 0 && MainEditor.SelectEnd != 0) {
+ if (MainEditor.SelectStart != MainEditorBackupVar.SelectStart) {
+ if (MainEditor.SelectStart >= MainEditorBackupVar.SelectStart && MainEditorBackupVar.SelectStart != 0) {
+ StartRow = (MainEditorBackupVar.SelectStart - 1) / SHELL_EDIT_MAX_LINE_SIZE + 1;
+ } else {
+ StartRow = (MainEditor.SelectStart - 1) / SHELL_EDIT_MAX_LINE_SIZE + 1;
+ }
+ } else {
+ StartRow = (MainEditor.SelectStart - 1) / SHELL_EDIT_MAX_LINE_SIZE + 1;
+ }
+
+ if (MainEditor.SelectEnd <= MainEditorBackupVar.SelectEnd) {
+ EndRow = (MainEditorBackupVar.SelectEnd - 1) / SHELL_EDIT_MAX_LINE_SIZE + 1;
+ } else {
+ EndRow = (MainEditor.SelectEnd - 1) / SHELL_EDIT_MAX_LINE_SIZE + 1;
+ }
+
+ //
+ // swap
+ //
+ if (StartRow > EndRow) {
+ Tmp = StartRow;
+ StartRow = EndRow;
+ EndRow = Tmp;
+ }
+
+ FStartRow = StartRow;
+
+ StartRow = 2 + StartRow - FileBuffer.LowVisibleRange.Row;
+ EndRow = 2 + EndRow - FileBuffer.LowVisibleRange.Row;
+
+ } else {
+ //
+ // not mouse selection actions
+ //
+ FStartRow = FileBuffer.LowVisibleRange.Row;
+ StartRow = 2;
+ EndRow = (MainEditor.ScreenSize.Row - 1);
+ }
//
// no line
@@ -638,15 +874,20 @@ FileBufferRefresh (
//
// print line at row
//
- FileBufferPrintLine (Line, Row);
+ FileBufferPrintLine (Line,
+ Row,
+ FileBuffer.LowVisibleRange.Row + Row - 2,
+ Orig,
+ New
+ );
Link = Link->ForwardLink;
Row++;
- } while (Link != FileBuffer.ListHead && Row <= (MainEditor.ScreenSize.Row - 1));
+ } while (Link != FileBuffer.ListHead && Row <= EndRow);
//
// while not file end and not screen full
//
- while (Row <= (MainEditor.ScreenSize.Row - 1)) {
+ while (Row <= EndRow) {
EditorClearLine (Row, MainEditor.ScreenSize.Column, MainEditor.ScreenSize.Row);
Row++;
}
@@ -3369,3 +3610,39 @@ FileBufferSetModified (
FileBuffer.FileModified = TRUE;
}
+
+/**
+ Get the size of the open buffer.
+
+ @retval The size in bytes.
+**/
+UINTN
+FileBufferGetTotalSize (
+ VOID
+ )
+{
+ UINTN Size;
+
+ EFI_EDITOR_LINE *Line;
+
+ //
+ // calculate the total size of whole line list's buffer
+ //
+ if (FileBuffer.Lines == NULL) {
+ return 0;
+ }
+
+ Line = CR (
+ FileBuffer.ListHead->BackLink,
+ EFI_EDITOR_LINE,
+ Link,
+ LINE_LIST_SIGNATURE
+ );
+ //
+ // one line at most 0x50
+ //
+ Size = SHELL_EDIT_MAX_LINE_SIZE * (FileBuffer.NumLines - 1) + Line->Size;
+
+ return Size;
+}
+