mirror of
https://gitcode.com/gitea/gitea.git
synced 2025-06-30 09:06:52 +08:00
Convert frontend code to typescript (#31559)
None of the frontend js/ts files was touched besides these two commands
(edit: no longer true, I touched one file in
61105d0618
because of a deprecation that was not showing before the rename).
`tsc` currently reports 778 errors, so I have disabled it in CI as
planned.
Everything appears to work fine.
This commit is contained in:
.eslintrc.yamlMakefilepackage-lock.jsonpackage.jsontsconfig.jsontypes.d.tsvitest.config.ts
web_src/js
bootstrap.test.tsbootstrap.tsglobals.tshtmx.tsindex.ts
webpack.config.jscomponents
ActionRunStatus.vueActivityHeatmap.vueContextPopup.vueDashboardRepoList.vueDiffCommitSelector.vueDiffFileList.vueDiffFileTree.vueDiffFileTreeItem.vuePullRequestMergeForm.vueRepoActionView.vueRepoActivityTopAuthors.vueRepoBranchTagSelector.vueRepoCodeFrequency.vueRepoContributors.vueRepoRecentCommits.vueScopedAccessTokenSelector.vue
features
admin
autofocus-end.tscaptcha.tscitation.tsclipboard.tscode-frequency.tscodeeditor.tscolorpicker.tscommon-button.tscommon-fetch-action.tscommon-form.tscommon-issue-list.test.tscommon-issue-list.tscommon-organization.tscommon-page.tscomp
ComboMarkdownEditor.tsConfirmModal.tsEasyMDEToolbarActions.tsEditorMarkdown.tsEditorUpload.test.tsEditorUpload.tsLabelEdit.tsQuickSubmit.tsReactionSelector.tsSearchUserBox.tsTextExpander.tsWebHookEditor.ts
contextpopup.tscontributors.tscopycontent.tsdropzone.tsemoji.tseventsource.sharedworker.tsfile-fold.tsheatmap.tsimagediff.tsinstall.tsnotification.tsorg-team.tspull-view-file.tsrecent-commits.tsrepo-branch.tsrepo-code.test.tsrepo-code.tsrepo-commit.tsrepo-common.tsrepo-diff-commit.tsrepo-diff-commitselect.tsrepo-diff-filetree.tsrepo-diff.tsrepo-editor.tsrepo-findfile.test.tsrepo-findfile.tsrepo-graph.tsrepo-home.tsrepo-issue-content.tsrepo-issue-edit.tsrepo-issue-list.tsrepo-issue-pr-form.tsrepo-issue-pr-status.tsrepo-issue.tsrepo-legacy.tsrepo-migrate.tsrepo-migration.tsrepo-projects.tsrepo-release.tsrepo-search.tsrepo-settings.tsrepo-template.tsrepo-unicode-escape.tsrepo-wiki.tssshkey-helper.tsstopwatch.tstablesort.tstribute.tsuser-auth-webauthn.tsuser-auth.tsuser-settings.tsmarkup
modules
dirauto.tsfetch.test.tsfetch.tsfomantic.ts
fomantic
sortable.tsstores.tstippy.tstoast.test.tstoast.tsworker.tsrender
standalone
svg.test.tssvg.tsutils.test.tsutils.tsutils
color.test.tscolor.tsdom.test.tsdom.tsimage.test.tsimage.tsmatch.test.tsmatch.tstime.test.tstime.tsurl.test.tsurl.ts
vendor
vitest.setup.tswebcomponents
45
web_src/js/render/ansi.ts
Normal file
45
web_src/js/render/ansi.ts
Normal file
@ -0,0 +1,45 @@
|
||||
import {AnsiUp} from 'ansi_up';
|
||||
|
||||
const replacements = [
|
||||
[/\x1b\[\d+[A-H]/g, ''], // Move cursor, treat them as no-op
|
||||
[/\x1b\[\d?[JK]/g, '\r'], // Erase display/line, treat them as a Carriage Return
|
||||
];
|
||||
|
||||
// render ANSI to HTML
|
||||
export function renderAnsi(line) {
|
||||
// create a fresh ansi_up instance because otherwise previous renders can influence
|
||||
// the output of future renders, because ansi_up is stateful and remembers things like
|
||||
// unclosed opening tags for colors.
|
||||
const ansi_up = new AnsiUp();
|
||||
ansi_up.use_classes = true;
|
||||
|
||||
if (line.endsWith('\r\n')) {
|
||||
line = line.substring(0, line.length - 2);
|
||||
} else if (line.endsWith('\n')) {
|
||||
line = line.substring(0, line.length - 1);
|
||||
}
|
||||
|
||||
if (line.includes('\x1b')) {
|
||||
for (const [regex, replacement] of replacements) {
|
||||
line = line.replace(regex, replacement);
|
||||
}
|
||||
}
|
||||
|
||||
if (!line.includes('\r')) {
|
||||
return ansi_up.ansi_to_html(line);
|
||||
}
|
||||
|
||||
// handle "\rReading...1%\rReading...5%\rReading...100%",
|
||||
// convert it into a multiple-line string: "Reading...1%\nReading...5%\nReading...100%"
|
||||
const lines = [];
|
||||
for (const part of line.split('\r')) {
|
||||
if (part === '') continue;
|
||||
const partHtml = ansi_up.ansi_to_html(part);
|
||||
if (partHtml !== '') {
|
||||
lines.push(partHtml);
|
||||
}
|
||||
}
|
||||
|
||||
// the log message element is with "white-space: break-spaces;", so use "\n" to break lines
|
||||
return lines.join('\n');
|
||||
}
|
Reference in New Issue
Block a user