Search Results for

Show / Hide Table of Contents

# Class HexView

An hex viewer and editor View over a System.IO.Stream

##### Inheritance

System.Object
Responder
View
HexView

##### Implements

System.IDisposable
System.ComponentModel.ISupportInitializeNotification
System.ComponentModel.ISupportInitialize

##### Remarks

HexView provides a hex editor on top of a seekable System.IO.Stream with the left side showing an hex dump of the values in the System.IO.Stream and the right side showing the contents (filtered to non-control sequence ASCII characters).

Users can switch from one side to the other by using the tab key.

To enable editing, set AllowEdits to true. When AllowEdits is true the user can make changes to the hexadecimal values of the System.IO.Stream. Any changes are tracked in the Edits property (a System.Collections.Generic.SortedDictionary`2) indicating the position where the changes were made and the new values. A convenience method, ApplyEdits(Stream) will apply the edits to the System.IO.Stream.

Control the first byte shown by setting the DisplayStart property to an offset in the stream.

##### Inherited Members

View.GetMinWidthHeight(Size)
View.SetMinWidthHeight()
View.UpdateTextFormatterText()
View.ProcessResizeView()
View.SetNeedsDisplay()
View.ClearLayoutNeeded()
View.SetNeedsDisplay(Rect)
View.SetChildNeedsDisplay()
View.Add(View)
View.Add(View[])
View.RemoveAll()
View.Remove(View)
View.BringSubviewToFront(View)
View.SendSubviewToBack(View)
View.SendSubviewBackwards(View)
View.BringSubviewForward(View)
View.Clear()
View.Clear(Rect)
View.ScreenToView(Int32, Int32)
View.ClipToBounds()
View.SetClip(Rect)
View.DrawFrame(Rect, Int32, Boolean)
View.DrawHotString(ustring, Attribute, Attribute)
View.DrawHotString(ustring, Boolean, ColorScheme)
View.Move(Int32, Int32, Boolean)
View.OnAdded(View)
View.OnRemoved(View)
View.OnLeave(View)
View.AddRune(Int32, Int32, Rune)
View.ClearNeedsDisplay()
View.OnDrawContent(Rect)
View.OnDrawContentComplete(Rect)
View.SetFocus()
View.InvokeKeybindings(KeyEvent)
View.AddKeyBinding(Key, Command)
View.ReplaceKeyBinding(Key, Key)
View.ContainsKeyBinding(Key)
View.ClearKeybindings()
View.ClearKeybinding(Key)
View.ClearKeybinding(Command)
View.AddCommand(Command, Func<Nullable<Boolean>>)
View.GetSupportedCommands()
View.GetKeyFromCommand(Command)
View.ProcessHotKey(KeyEvent)
View.ProcessColdKey(KeyEvent)
View.OnKeyDown(KeyEvent)
View.OnKeyUp(KeyEvent)
View.EnsureFocus()
View.FocusFirst()
View.FocusLast()
View.FocusPrev()
View.FocusNext()
View.LayoutSubviews()
View.ToString()
View.GetAutoSize()
View.GetHotKeySpecifierLength(Boolean)
View.GetTextFormatterBoundsSize()
View.GetBoundsTextFormatterSize()
View.OnMouseEnter(MouseEvent)
View.OnMouseLeave(MouseEvent)
View.OnMouseEvent(MouseEvent)
View.OnMouseClick(View.MouseEventArgs)
View.OnCanFocusChanged()
View.OnEnabledChanged()
View.OnVisibleChanged()
View.Dispose(Boolean)
View.BeginInit()
View.EndInit()
View.SetWidth(Int32, Int32)
View.SetHeight(Int32, Int32)
View.GetCurrentWidth(Int32)
View.GetCurrentHeight(Int32)
View.GetNormalColor()
View.GetTopSuperView()
View.HotKey
View.HotKeySpecifier
View.Shortcut
View.ShortcutTag
View.ShortcutAction
View.Data
View.Driver
View.Subviews
View.TabIndexes
View.TabIndex
View.TabStop
View.CanFocus
View.Id
View.IsCurrentTop
View.WantMousePositionReports
View.WantContinuousButtonPressed
View.LayoutStyle
View.Bounds
View.X
View.Y
View.Width
View.Height
View.ForceValidatePosDim
View.TextFormatter
View.SuperView
View.HasFocus
View.Focused
View.MostFocused
View.ColorScheme
View.Text
View.AutoSize
View.PreserveTrailingSpaces
View.TextAlignment
View.VerticalTextAlignment
View.TextDirection
View.IsInitialized
View.IsAdded
View.Enabled
View.Visible
View.Border
View.Added
View.Removed
View.Enter
View.Leave
View.MouseEnter
View.MouseLeave
View.MouseClick
View.CanFocusChanged
View.EnabledChanged
View.VisibleChanged
View.HotKeyChanged
View.DrawContent
View.DrawContentComplete
View.KeyPress
View.KeyDown
View.KeyUp
View.LayoutStarted
View.LayoutComplete
View.Initialized
Responder.Dispose()

###### Namespace: Terminal.Gui

###### Assembly: Terminal.Gui.dll

##### Syntax

    public class HexView : View

### Constructors

#### HexView()

Initializes a HexView class using Computed layout.

##### Declaration

    public HexView()

#### HexView(Stream)

Initializes a HexView class using Computed layout.

##### Declaration

    public HexView(Stream source)

##### Parameters

Type | Name | Description
--- | --- | ---
System.IO.Stream | source | The System.IO.Stream to view and edit as hex, this System.IO.Stream must support seeking, or an exception will be thrown.

### Properties

#### AllowEdits

Gets or sets whether this HexView allow editing of the System.IO.Stream of the underlying System.IO.Stream.

##### Declaration

    public bool AllowEdits { get; set; }

##### Property Value

Type | Description
--- | ---
System.Boolean | `true` if allow edits; otherwise, `false`.

#### BytesPerLine

The bytes length per line.

##### Declaration

    public int BytesPerLine { get; }

##### Property Value

Type | Description
--- | ---
System.Int32 |

#### CursorPosition

Gets the current cursor position starting at one for both, line and column.

##### Declaration

    public Point CursorPosition { get; }

##### Property Value

Type | Description
--- | ---
Point |

#### DesiredCursorVisibility

Get / Set the wished cursor when the field is focused

##### Declaration

    public CursorVisibility DesiredCursorVisibility { get; set; }

##### Property Value

Type | Description
--- | ---
CursorVisibility |

#### DisplayStart

Sets or gets the offset into the System.IO.Stream that will displayed at the top of the HexView

##### Declaration

    public long DisplayStart { get; set; }

##### Property Value

Type | Description
--- | ---
System.Int64 | The display start.

#### Edits

Gets a System.Collections.Generic.SortedDictionary`2 describing the edits done to the HexView. Each Key indicates an offset where an edit was made and the Value is the changed byte.

##### Declaration

    public IReadOnlyDictionary<long, byte> Edits { get; }

##### Property Value

Type | Description
--- | ---
System.Collections.Generic.IReadOnlyDictionary<System.Int64, System.Byte> | The edits.

#### Frame

Gets or sets the frame for the view. The frame is relative to the view's container (SuperView).

##### Declaration

    public override Rect Frame { get; set; }

##### Property Value

Type | Description
--- | ---
Rect | The frame.

##### Overrides

View.Frame

#### Position

Gets the current character position starting at one, related to the System.IO.Stream.

##### Declaration

    public long Position { get; }

##### Property Value

Type | Description
--- | ---
System.Int64 |

#### Source

Sets or gets the System.IO.Stream the HexView is operating on; the stream must support seeking (System.IO.Stream.CanSeek == true).

##### Declaration

    public Stream Source { get; set; }

##### Property Value

Type | Description
--- | ---
System.IO.Stream | The source.

### Methods

#### ApplyEdits(Stream)

This method applies and edits made to the System.IO.Stream and resets the contents of the Edits property.

##### Declaration

    public void ApplyEdits(Stream stream = null)

##### Parameters

Type | Name | Description
--- | --- | ---
System.IO.Stream | stream | If provided also applies the changes to the passed System.IO.Stream

#### DiscardEdits()

This method discards the edits made to the System.IO.Stream by resetting the contents of the Edits property.

##### Declaration

    public void DiscardEdits()

#### MouseEvent(MouseEvent)

Method invoked when a mouse event is generated

##### Declaration

    public override bool MouseEvent(MouseEvent me)

##### Parameters

Type | Name | Description
--- | --- | ---
MouseEvent | me |

##### Returns

Type | Description
--- | ---
System.Boolean | `true`, if the event was handled, `false` otherwise.

##### Overrides

Responder.MouseEvent(MouseEvent)

#### OnEdited(KeyValuePair<Int64, Byte>)

Method used to invoke the Edited event passing the System.Collections.Generic.KeyValuePair<, >.

##### Declaration

    public virtual void OnEdited(KeyValuePair<long, byte> keyValuePair)

##### Parameters

Type | Name | Description
--- | --- | ---
System.Collections.Generic.KeyValuePair<System.Int64, System.Byte> | keyValuePair | The key value pair.

#### OnEnter(View)

Method invoked when a view gets focus.

##### Declaration

    public override bool OnEnter(View view)

##### Parameters

Type | Name | Description
--- | --- | ---
View | view | The view that is losing focus.

##### Returns

Type | Description
--- | ---
System.Boolean | `true`, if the event was handled, `false` otherwise.

##### Overrides

View.OnEnter(View)

#### OnPositionChanged()

Method used to invoke the PositionChanged event passing the HexView.HexViewEventArgs arguments.

##### Declaration

    public virtual void OnPositionChanged()

#### PositionCursor()

Positions the cursor in the right position based on the currently focused view in the chain.

##### Declaration

    public override void PositionCursor()

##### Overrides

View.PositionCursor()

#### ProcessKey(KeyEvent)

If the view is focused, gives the view a chance to process the keystroke.

##### Declaration

    public override bool ProcessKey(KeyEvent keyEvent)

##### Parameters

Type | Name | Description
--- | --- | ---
KeyEvent | keyEvent | Contains the details about the key that produced the event.

##### Returns

Type | Description
--- | ---
System.Boolean |

##### Overrides

View.ProcessKey(KeyEvent)

#### Redraw(Rect)

Redraws this view and its subviews; only redraws the views that have been flagged for a re-display.

##### Declaration

    public override void Redraw(Rect bounds)

##### Parameters

Type | Name | Description
--- | --- | ---
Rect | bounds | The bounds (view-relative region) to redraw.

##### Overrides

View.Redraw(Rect)

### Events

#### Edited

Event to be invoked when an edit is made on the System.IO.Stream.

##### Declaration

    public event Action<KeyValuePair<long, byte>> Edited

##### Event Type

Type | Description
--- | ---
System.Action<System.Collections.Generic.KeyValuePair<System.Int64, System.Byte>> |

#### PositionChanged

Event to be invoked when the position and cursor position changes.

##### Declaration

    public event Action<HexView.HexViewEventArgs> PositionChanged

##### Event Type

Type | Description
--- | ---
System.Action<HexView.HexViewEventArgs> |

### Implements

System.IDisposable
System.ComponentModel.ISupportInitializeNotification
System.ComponentModel.ISupportInitialize