Skip to content

Commit

Permalink
upgrade Ωedit™ to v0.9.75
Browse files Browse the repository at this point in the history
  • Loading branch information
scholarsmate authored and stricklandrbls committed Oct 23, 2023
1 parent 2346065 commit 2fba695
Show file tree
Hide file tree
Showing 13 changed files with 475 additions and 311 deletions.
62 changes: 47 additions & 15 deletions src/dataEditor/dataEditorClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
getClient,
getClientVersion,
getComputedFileSize,
getContentType,

Check failure on line 33 in src/dataEditor/dataEditorClient.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: macos-11, Node: 16)

Module '"@omega-edit/client"' has no exported member 'getContentType'.

Check failure on line 33 in src/dataEditor/dataEditorClient.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: macos-11, Node: 18)

Module '"@omega-edit/client"' has no exported member 'getContentType'.

Check failure on line 33 in src/dataEditor/dataEditorClient.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: ubuntu-20.04, Node: 16)

Module '"@omega-edit/client"' has no exported member 'getContentType'.

Check failure on line 33 in src/dataEditor/dataEditorClient.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: ubuntu-20.04, Node: 18)

Module '"@omega-edit/client"' has no exported member 'getContentType'.

Check failure on line 33 in src/dataEditor/dataEditorClient.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: windows-2019, Node: 16)

Module '"@omega-edit/client"' has no exported member 'getContentType'.
getCounts,
getLogger,
getServerHeartbeat,
Expand Down Expand Up @@ -248,14 +249,17 @@ export class DataEditorClient implements vscode.Disposable {
assert(this.omegaSessionId.length > 0, 'omegaSessionId is not set')
addActiveSession(this.omegaSessionId)

this.contentType = createSessionResponse.hasContentType()
? (createSessionResponse.getContentType() as string)
: 'unknown'
assert(this.contentType.length > 0, 'contentType is not set')

this.fileSize = createSessionResponse.hasFileSize()
? (createSessionResponse.getFileSize() as number)
: 0

const contentTypeResponse = await getContentType(
this.omegaSessionId,
0,
Math.min(1024, this.fileSize)
)
this.contentType = contentTypeResponse.getContentType()
assert(this.contentType.length > 0, 'contentType is not set')
} catch {
const msg = `Failed to create session for ${this.fileToEdit}`
getLogger().error({
Expand Down Expand Up @@ -669,12 +673,12 @@ async function createDataEditorWebviewPanel(
configureOmegaEditPort()
assert(omegaEditPort > 0, 'omega edit port not configured')

// only start uo the server if one is not already running
// only start up the server if one is not already running
if (!(await checkServerListening(omegaEditPort, OMEGA_EDIT_HOST))) {
await setupLogging()
setAutoFixViewportDataLength(true)
await serverStart()
client = getClient(omegaEditPort, OMEGA_EDIT_HOST)
client = await getClient(omegaEditPort, OMEGA_EDIT_HOST)
assert(
await checkServerListening(omegaEditPort, OMEGA_EDIT_HOST),
'server not listening'
Expand Down Expand Up @@ -1138,9 +1142,9 @@ async function serverStart() {
const animationInterval = 400 // ms per frame
const animationFrames = ['', '.', '..', '...']
const animationIntervalId = setInterval(() => {
const frame = animationFrames[animationFrame % animationFrames.length]
statusBarItem.text = `${serverStartingText} ${frame}`
++animationFrame
statusBarItem.text = `${serverStartingText} ${
animationFrames[++animationFrame % animationFrames.length]
}`
}, animationInterval)
const config = vscode.workspace.getConfiguration('dataEditor')
const logLevel =
Expand All @@ -1152,6 +1156,8 @@ async function serverStart() {
logLevel
)
if (!fs.existsSync(logConfigFile)) {
clearInterval(animationIntervalId)
statusBarItem.dispose()
throw new Error(`Log config file '${logConfigFile}' not found`)
}

Expand All @@ -1173,31 +1179,57 @@ async function serverStart() {
}, SERVER_START_TIMEOUT * 1000)
}),
])) as number | undefined
clearInterval(animationIntervalId)
if (serverPid === undefined || serverPid <= 0) {
statusBarItem.dispose()
throw new Error('Server failed to start or PID is invalid')
}
const clientVersion = getClientVersion()
serverInfo = await getServerInfo()
// this makes sure the server if fully online and ready to take requests
statusBarItem.text = `Initializing Ωedit server on port ${omegaEditPort}`
for (let i = 1; i <= 60; ++i) {
try {
await getServerInfo()
break
} catch (err) {
statusBarItem.text = `Initializing Ωedit server on port ${omegaEditPort} (${i}/60)`
}
// wait 1 second before trying again
await new Promise((resolve) => {
setTimeout(() => {
resolve(true)
}, 1000)
})
}
try {
serverInfo = await getServerInfo()
} catch (err) {
statusBarItem.dispose()
await serverStop()
throw new Error('Server failed to initialize')
}
statusBarItem.text = `Ωedit server on port ${omegaEditPort} initialized`
const serverVersion = serverInfo.serverVersion
// if the OS is not Windows, check that the server PID matches the one started
// NOTE: serverPid is the PID of the server wrapper script on Windows
if (
!os.platform().toLowerCase().startsWith('win') &&
serverInfo.serverProcessId !== serverPid
) {
statusBarItem.dispose()
throw new Error(
`server PID mismatch ${serverInfo.serverProcessId} != ${serverPid}`
)
}
const clientVersion = getClientVersion()
if (serverVersion !== clientVersion) {
statusBarItem.dispose()
throw new Error(
`Server version ${serverVersion} and client version ${clientVersion} must match`
)
}
// get an initial heartbeat to ensure the server is up and running
// get an initial heartbeat
await getHeartbeat()
clearInterval(animationIntervalId)
statusBarItem.text = `Ωedit server v${serverVersion} started on port ${omegaEditPort} with PID ${serverInfo.serverProcessId}`
statusBarItem.text = `Ωedit server v${serverVersion} ready on port ${omegaEditPort} with PID ${serverInfo.serverProcessId}`
setTimeout(() => {
statusBarItem.dispose()
}, 5000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ limitations under the License.
seekOffsetInput,
visableViewports,
dataDislayLineAmount,
replaceQuery,
searchResultsUpdated,
} from '../../../stores'
import {
EditByteModes,
Expand Down Expand Up @@ -62,10 +64,12 @@ limitations under the License.
type CSSThemeClass,
} from '../../../utilities/colorScheme'
import {
selectionHighlights,
searchResultsHighlights,
updateSearchResultsHighlights,
searchResultsUpdated,
CATEGORY_ONE_MASK,
CATEGORY_TWO_MASK,
viewportByteIndicators,
type ByteValueIndications,
IndicatorCategoryShift,
byteCategoryValue,
} from '../../../utilities/highlights'
import { bytesPerRow } from '../../../stores'
export let awaitViewportSeek: boolean
Expand Down Expand Up @@ -169,7 +173,7 @@ limitations under the License.
bytes: Array<ByteValue>
highlight: 'even' | 'odd'
}
enum ViewportScrollDirection {
DECREMENT = -1,
NONE = 0,
Expand All @@ -181,10 +185,13 @@ limitations under the License.
let viewportDataContainer: HTMLDivElement
let selectedByteElement: HTMLDivElement
let themeClass: CSSThemeClass
let activeSelection: Uint8Array
let lineTopFileOffset: number
let searchResults: Uint8Array
let makingSelection = false
$: {
makingSelection =
$selectionDataStore.startOffset >= 0 && $selectionDataStore.active === false
}
onMount(() => {
viewportDataContainer = document.getElementById(
CONTAINER_ID
Expand Down Expand Up @@ -215,13 +222,10 @@ limitations under the License.
}
$: {
activeSelection = $selectionHighlights
searchResults = $searchResultsHighlights
if (
(viewportData.fileOffset >= 0 &&
!awaitViewportSeek &&
$dataFeedLineTop >= 0) ||
$searchResultsUpdated
viewportData.fileOffset >= 0 &&
!awaitViewportSeek &&
$dataFeedLineTop >= 0
) {
if (
viewportLines.length !== 0 &&
Expand All @@ -243,6 +247,11 @@ limitations under the License.
}
}
$: byteElementWidth = byteDivWidthFromRadix(dataRadix)
$: {
viewportByteIndicators.updateSelectionIndications($selectionDataStore.startOffset, $selectionDataStore.endOffset)
viewportByteIndicators.updateSearchIndications($searchQuery.searchResults, $searchQuery.byteLength)
viewportByteIndicators.updateReplaceIndications($replaceQuery.results, viewportData.fileOffset)
}
function generate_line_data(
startIndex: number,
Expand Down Expand Up @@ -359,21 +368,21 @@ limitations under the License.
: atViewportHead && !atFileHead
}
function mousedown(event: CustomEvent<ByteSelectionEvent>) {
function mousedown(event: ByteSelectionEvent) {
selectionDataStore.update((selections) => {
selections.active = false
selections.startOffset = event.detail.targetByte.offset
selections.startOffset = event.targetByte.offset
selections.endOffset = -1
selections.originalEndOffset = -1
return selections
})
}
function mouseup(event: CustomEvent<ByteSelectionEvent>) {
function mouseup(event: ByteSelectionEvent) {
selectionDataStore.update((selections) => {
selections.active = true
selections.endOffset = event.detail.targetByte.offset
selections.originalEndOffset = event.detail.targetByte.offset
selections.endOffset = event.targetByte.offset
selections.originalEndOffset = event.targetByte.offset
adjust_event_offsets()
return selections
})
Expand All @@ -383,7 +392,7 @@ limitations under the License.
return
}
set_byte_selection(event.detail)
set_byte_selection(event)
}
function adjust_event_offsets() {
Expand Down Expand Up @@ -471,6 +480,48 @@ limitations under the License.
}
}
function mouseover_handler(e: Event) {
if(!makingSelection) return
const target = e.target as HTMLDivElement
let targetViewportIndex = parseInt(target.getAttribute('offset')!)
selectionDataStore.update((selections) => {
selections.endOffset = targetViewportIndex
adjust_event_offsets()
return selections
})
}
function mouseclick_handler(e: Event) {
const type = e.type
const targetElement = e.target as HTMLDivElement
let targetViewportIndex = parseInt(targetElement.getAttribute('offset')!)
let byteText: string | undefined = targetElement.innerHTML
let byteValue: number = byteText === undefined ? -1 : parseInt(byteText)
if (targetElement.id.includes('logical')) byteText = String.fromCharCode(byteValue)
let targetByte: ByteValue = {
offset: targetViewportIndex,
text: byteText,
value: byteValue
}
const byteSelectionEvent: ByteSelectionEvent =
{
targetElement: targetElement,
targetByte: targetByte,
fromViewport: targetElement.id.includes('logical') ? 'logical' : 'physical',
}
switch(type) {
case 'mousedown':
mousedown(byteSelectionEvent)
break
case 'mouseup':
mouseup(byteSelectionEvent)
}
}
window.addEventListener('keydown', navigation_keydown_event)
window.addEventListener('message', (msg) => {
switch (msg.data.command) {
Expand All @@ -485,16 +536,11 @@ limitations under the License.
selectedByteElement = document.getElementById(
$selectedByte.offset.toString()
) as HTMLDivElement
updateSearchResultsHighlights(
$searchQuery.searchResults,
viewportData.fileOffset,
$searchQuery.byteLength
)
}
break
}
})
</script>

{#if $selectionDataStore.active && $editMode == EditByteModes.Single}
Expand All @@ -508,7 +554,13 @@ limitations under the License.
{/key}
{/if}

<div class="container" style:height id={CONTAINER_ID}>
<svelte:window on:mousemove={mouseover_handler}/>
<!-- svelte-ignore a11y-mouse-events-have-key-events -->
<!-- svelte-ignore a11y-click-events-have-key-events -->
<div class="container" style:height id={CONTAINER_ID}
on:mousedown={mouseclick_handler}
on:mouseup={mouseclick_handler}
>
{#each viewportLines as viewportLine, i}
<div class={`line ${viewportLine.highlight} ${themeClass}`}>
<div class="address" id="address">
Expand All @@ -523,17 +575,12 @@ limitations under the License.
{#each viewportLine.bytes as byte}
<DataValue
{byte}
isSelected={activeSelection[byte.offset] === 1}
possibleSelection={activeSelection[byte.offset] === 2}
isSearchResult={searchResults[byte.offset] >>
activeSelection[byte.offset]}
id={'physical'}
radix={dataRadix}
indicators={{
cat1: byteCategoryValue($viewportByteIndicators[byte.offset] & CATEGORY_ONE_MASK, IndicatorCategoryShift.CategoryOne),
cat2: byteCategoryValue($viewportByteIndicators[byte.offset] & CATEGORY_TWO_MASK, IndicatorCategoryShift.CategoryTwo) }}
width={byteElementWidth}
disabled={byte.value === -1}
bind:selectionData={$selectionDataStore}
on:mouseup={mouseup}
on:mousedown={mousedown}
/>
{/each}
</div>
Expand All @@ -546,17 +593,12 @@ limitations under the License.
{#each viewportLine.bytes as byte}
<DataValue
{byte}
isSelected={activeSelection[byte.offset] === 1}
possibleSelection={activeSelection[byte.offset] === 2}
isSearchResult={searchResults[byte.offset] >>
activeSelection[byte.offset]}
indicators={{
cat1: byteCategoryValue($viewportByteIndicators[byte.offset] & CATEGORY_ONE_MASK, IndicatorCategoryShift.CategoryOne),
cat2: byteCategoryValue($viewportByteIndicators[byte.offset] & CATEGORY_TWO_MASK, IndicatorCategoryShift.CategoryTwo) }}
id={'logical'}
radix={dataRadix}
width={byteElementWidth}
disabled={byte.value === -1}
bind:selectionData={$selectionDataStore}
on:mouseup={mouseup}
on:mousedown={mousedown}
/>
{/each}
</div>
Expand Down Expand Up @@ -697,15 +739,6 @@ limitations under the License.
flex-direction: column;
margin: 0 5px;
}
span.submit-bpr-input {
font-size: 14px;
cursor: pointer;
margin: 0 5px;
}
span.submit-bpr-input:hover {
font-weight: bold;
cursor: pointer;
}
div.container {
display: flex;
flex-direction: column;
Expand Down
Loading

0 comments on commit 2fba695

Please sign in to comment.