Move project into src directory

This commit is contained in:
Stone_Red
2024-02-01 08:48:24 +01:00
parent c22478bc7f
commit b83e4ad06d
27 changed files with 0 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
using TextLore.Models;
namespace TextLore.Commands;
public class TestCommand : Command
{
public override string Name => "test";
public override string Description => "A test command.";
public override Task<bool> Execute(ConsoleOutput consoleOutput, string[] args)
{
consoleOutput.WriteLine("This is a test command.");
return Task.FromResult(true);
}
}
+21
View File
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<base href="/" />
<link rel="stylesheet" href="bootstrap/bootstrap.min.css" />
<link rel="stylesheet" href="app.css" />
<link rel="stylesheet" href="console.css" />
<link rel="stylesheet" href="TextLore.styles.css" />
<link rel="icon" type="image/png" href="favicon.ico" />
<HeadOutlet @rendermode="InteractiveServer" />
</head>
<body>
<Routes @rendermode="InteractiveServer" />
<script src="_framework/blazor.web.js"></script>
</body>
</html>
@@ -0,0 +1,26 @@
@inherits LayoutComponentBase
<div class="fixed-top p-4">
<h1 class="text-white-50 mb-0">TextLore — Stone_Red</h1>
<div>
<a class="link-info" href="https://github.me.stone-red.net/TextLore">https://github.me.stone-red.net/TextLore</a>
</div>
</div>
<div class="main">
<noscript>
<div class="alert alert-danger" role="alert">
<strong>JavaScript is disabled!</strong> This application requires JavaScript to be enabled. Please enable JavaScript in your browser and reload this page.
</div>
</noscript>
<div class="content px-4">
@Body
</div>
</div>
<div id="blazor-error-ui">
An unhandled error has occurred.
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>
@@ -0,0 +1,96 @@
.page {
position: relative;
display: flex;
flex-direction: column;
}
main {
flex: 1;
}
.sidebar {
background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%);
}
.top-row {
background-color: #f7f7f7;
border-bottom: 1px solid #d6d5d5;
justify-content: flex-end;
height: 3.5rem;
display: flex;
align-items: center;
}
.top-row ::deep a, .top-row ::deep .btn-link {
white-space: nowrap;
margin-left: 1.5rem;
text-decoration: none;
}
.top-row ::deep a:hover, .top-row ::deep .btn-link:hover {
text-decoration: underline;
}
.top-row ::deep a:first-child {
overflow: hidden;
text-overflow: ellipsis;
}
@media (max-width: 640.98px) {
.top-row {
justify-content: space-between;
}
.top-row ::deep a, .top-row ::deep .btn-link {
margin-left: 0;
}
}
@media (min-width: 641px) {
.page {
flex-direction: row;
}
.sidebar {
width: 250px;
height: 100vh;
position: sticky;
top: 0;
}
.top-row {
position: sticky;
top: 0;
z-index: 1;
}
.top-row.auth ::deep a:first-child {
flex: 1;
text-align: right;
width: 0;
}
.top-row, article {
padding-left: 2rem !important;
padding-right: 1.5rem !important;
}
}
#blazor-error-ui {
background: lightyellow;
bottom: 0;
box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
display: none;
left: 0;
padding: 0.6rem 1.25rem 0.7rem 1.25rem;
position: fixed;
width: 100%;
z-index: 1000;
}
#blazor-error-ui .dismiss {
cursor: pointer;
position: absolute;
right: 0.75rem;
top: 0.5rem;
}
@@ -0,0 +1,18 @@
@page "/counter"
<PageTitle>Counter</PageTitle>
<h1>Counter</h1>
<p role="status">Current count: @currentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
@code {
private int currentCount = 0;
private void IncrementCount()
{
currentCount++;
}
}
+36
View File
@@ -0,0 +1,36 @@
@page "/Error"
@using System.Diagnostics
<PageTitle>Error</PageTitle>
<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>
@if (ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@RequestId</code>
</p>
}
<h3>Development Mode</h3>
<p>
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
</p>
@code{
[CascadingParameter]
private HttpContext? HttpContext { get; set; }
private string? RequestId { get; set; }
private bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
protected override void OnInitialized() =>
RequestId = Activity.Current?.Id ?? HttpContext?.TraceIdentifier;
}
+12
View File
@@ -0,0 +1,12 @@
@page "/"
@using TextLore.Commands
@using TextLore.Models
<PageTitle>Home</PageTitle>
<TextLore.Components.Shared.Console Commands="commands" />
@code
{
Command[] commands = [new TestCommand()];
}
@@ -0,0 +1,64 @@
@page "/weather"
@attribute [StreamRendering]
<PageTitle>Weather</PageTitle>
<h1>Weather</h1>
<p>This component demonstrates showing data.</p>
@if (forecasts == null)
{
<p><em>Loading...</em></p>
}
else
{
<table class="table">
<thead>
<tr>
<th>Date</th>
<th>Temp. (C)</th>
<th>Temp. (F)</th>
<th>Summary</th>
</tr>
</thead>
<tbody>
@foreach (var forecast in forecasts)
{
<tr>
<td>@forecast.Date.ToShortDateString()</td>
<td>@forecast.TemperatureC</td>
<td>@forecast.TemperatureF</td>
<td>@forecast.Summary</td>
</tr>
}
</tbody>
</table>
}
@code {
private WeatherForecast[]? forecasts;
protected override async Task OnInitializedAsync()
{
// Simulate asynchronous loading to demonstrate streaming rendering
await Task.Delay(500);
var startDate = DateOnly.FromDateTime(DateTime.Now);
var summaries = new[] { "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" };
forecasts = Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = startDate.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = summaries[Random.Shared.Next(summaries.Length)]
}).ToArray();
}
private class WeatherForecast
{
public DateOnly Date { get; set; }
public int TemperatureC { get; set; }
public string? Summary { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
}
+6
View File
@@ -0,0 +1,6 @@
<Router AppAssembly="typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)" />
<FocusOnNavigate RouteData="routeData" Selector="h1" />
</Found>
</Router>
@@ -0,0 +1,112 @@
@using Microsoft.AspNetCore.Components.Forms
@using TextLore.Models
<div id="console">
<div id="header">
<h4>@Name</h4>
@if (ShowDate)
{
<h5> @DateTime.UtcNow.ToLongDateString()</h5>
}
@if (!string.IsNullOrWhiteSpace(Description))
{
<h6>> @Description</h6>
}
</div>
<div id="container">
<EditForm OnSubmit="Execute" autocomplete="off" Model="ConsoleInput" novalidate>
<div id="input-line" class="input-line">
<div class="prompt">
Command >
</div>
<div>
<InputText @ref="inputText" id="commandline" autocomplete="off" class="cmdline" disabled="@disabled" placeholder="@Placeholder" @bind-Value="@ConsoleInput.Text" />
</div>
</div>
</EditForm>
<pre>
<code>@((MarkupString)running)</code>
<code>@((MarkupString)output)</code>
</pre>
</div>
</div>
@code {
[Parameter, EditorRequired]
public string Name { get; set; } = "Console";
[Parameter]
public string? Description { get; set; }
[Parameter]
public bool ShowDate { get; set; } = true;
public string Placeholder => $"Enter a command{(HelpCommand is null ? "." : ", type 'help' for avaliable commands.")}";
public ConsoleInput ConsoleInput { get; set; } = new();
public ConsoleOutput ConsoleOutput { get; set; } = new();
[Parameter, EditorRequired]
public IEnumerable<Command> Commands { get; set; } = [];
[Parameter]
public Command? HelpCommand { get; set; }
private string output { get; set; } = "";
private string running { get; set; } = "";
private bool disabled { get; set; } = false;
private InputText? inputText;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (inputText?.Element is not null)
{
await inputText.Element.Value.FocusAsync();
}
}
protected override void OnInitialized()
{
ConsoleOutput.OnOutput += WriteOutput;
}
public async Task Execute(EditContext context)
{
Command? command = Commands.FirstOrDefault(c=>c.Name.Equals(ConsoleInput.Text));
command ??= HelpCommand;
if(command is null)
{
running = $"[Failed] Command '{ConsoleInput.Text}' not found!";
ConsoleInput.Text = string.Empty;
return;
}
disabled = true;
running = $"<p>";
running += $"<span class='header'>{ConsoleInput.Time.ToString("HH:mm")} > </span><span class='command'>{ConsoleInput.Text}{Environment.NewLine}</span>";
bool success = await command.Execute(ConsoleOutput, []);
running += "</p>";
output = running + output;
running = success ? $"[Success]" : $"[Failed]";
ConsoleInput.Text = string.Empty;
disabled = false;
StateHasChanged();
}
public void WriteOutput(object? sender, ConsoleOutputEventArgs e)
{
string newOutput = e.Message;
output = newOutput + output;
StateHasChanged();
}
}
+10
View File
@@ -0,0 +1,10 @@
@using System.Net.Http
@using System.Net.Http.Json
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using static Microsoft.AspNetCore.Components.Web.RenderMode
@using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.JSInterop
@using TextLore
@using TextLore.Components
+11
View File
@@ -0,0 +1,11 @@
namespace TextLore.Models;
public abstract class Command
{
public abstract string Name { get; }
public abstract string Description { get; }
public virtual string Usage { get; } = string.Empty;
public virtual string[] Aliases { get; } = [];
public abstract Task<bool> Execute(ConsoleOutput consoleOutput, string[] args);
}
+7
View File
@@ -0,0 +1,7 @@
namespace TextLore.Models;
public class ConsoleInput
{
public string Text { get; set; } = string.Empty;
public DateTime Time { get; } = DateTime.UtcNow;
}
@@ -0,0 +1,9 @@
namespace TextLore.Models;
public enum ConsoleMessageType
{
Default,
Info,
Warning,
Error
}
+46
View File
@@ -0,0 +1,46 @@
namespace TextLore.Models;
public class ConsoleOutput
{
public event EventHandler<ConsoleOutputEventArgs>? OnOutput;
public void Write(string message, ConsoleMessageType consoleMessageType = ConsoleMessageType.Default)
{
OnOutput?.Invoke(this, new(message, consoleMessageType));
}
public void WriteLine(string message)
{
Write(message + Environment.NewLine);
}
public void WriteError(string message)
{
Write($"[ERROR] {message}", ConsoleMessageType.Error);
}
public void WriteErrorLine(string message)
{
WriteError(message + Environment.NewLine);
}
public void WriteWarning(string message)
{
Write($"[WARNING] {message}", ConsoleMessageType.Warning);
}
public void WriteWarningLine(string message)
{
WriteWarning(message + Environment.NewLine);
}
public void WriteInfo(string message)
{
Write($"[INFO] {message}", ConsoleMessageType.Info);
}
public void WriteInfoLine(string message)
{
WriteInfo(message + Environment.NewLine);
}
}
@@ -0,0 +1,8 @@
namespace TextLore.Models;
public class ConsoleOutputEventArgs(string message, ConsoleMessageType messageType) : EventArgs
{
public string Message { get; } = message;
public ConsoleMessageType MessageType { get; } = messageType;
}
+27
View File
@@ -0,0 +1,27 @@
using TextLore.Components;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseAntiforgery();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
app.Run();
@@ -0,0 +1,38 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:2409",
"sslPort": 44332
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5247",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7031;http://localhost:5247",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
+9
View File
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
</Project>
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
+9
View File
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
+143
View File
@@ -0,0 +1,143 @@
@import url('open-iconic/font/css/open-iconic-bootstrap.min.css');
html, body {
font-family: monospace, Helvetica, Arial, sans-serif;
background-color: black;
}
a, .btn-link {
color: #0366d6;
}
.btn-primary {
color: #fff;
background-color: #1b6ec2;
border-color: #1861ac;
}
app {
position: relative;
display: flex;
flex-direction: column;
}
.main {
flex: 1;
margin-top: 10rem;
max-height: calc(100vh - 13rem);
height: calc(100vh - 13rem);
overflow-y: hidden;
}
#console::before {
position: absolute;
content: "";
height: 10%;
width: 100%;
bottom: 3rem;
left: 0;
background: linear-gradient(transparent 0%, black 100%);
}
.sidebar {
background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%);
}
.sidebar .navbar-brand {
font-size: 1.1rem;
}
.sidebar .oi {
width: 2rem;
font-size: 1.1rem;
vertical-align: text-top;
top: -2px;
}
.nav-item {
font-size: 0.9rem;
padding-bottom: 0.5rem;
}
.nav-item:first-of-type {
padding-top: 1rem;
}
.nav-item:last-of-type {
padding-bottom: 1rem;
}
.nav-item a {
color: #d7d7d7;
border-radius: 4px;
height: 3rem;
display: flex;
align-items: center;
line-height: 3rem;
}
.nav-item a.active {
background-color: rgba(255,255,255,0.25);
color: white;
}
.nav-item a:hover {
background-color: rgba(255,255,255,0.1);
color: white;
}
.content {
padding-top: 1.1rem;
}
.navbar-toggler {
background-color: rgba(255, 255, 255, 0.1);
}
.valid.modified:not([type=checkbox]) {
outline: 1px solid #26b050;
}
.invalid {
outline: 1px solid red;
}
.validation-message {
color: red;
}
@media (max-width: 767.98px) {
}
@media (min-width: 768px) {
app {
flex-direction: row;
}
.main {
margin-top: 8rem;
max-height: calc(100vh - 11rem);
height: calc(100vh - 11rem);
}
.sidebar {
width: 250px;
height: 100vh;
position: sticky;
top: 0;
}
.navbar-toggler {
display: none;
}
.sidebar .collapse {
/* Never collapse the sidebar for wide screens */
display: block;
}
}
::selection {
background: #FF5E99;
}
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+116
View File
@@ -0,0 +1,116 @@
#console {
width: 100%;
height: 100%;
margin: 0;
font-size: 13pt;
font-family: monospace;
color: white;
background-color: black;
}
#console #header pre {
font-size: 9pt;
color: #757575;
margin-left: -50px;
}
#console #container {
padding: .1em 1.5em 1em 1em;
margin-top: 20px;
}
#console #container pre {
height: auto;
margin-bottom: -40px;
color: #757575;
}
#console #container pre .header {
font-weight: bold;
color: #96b38a;
}
#console #container pre .command {
color: yellow;
}
#console #container p {
margin: 0px;
margin-top: 10px;
}
#console #container .prgs {
margin-top: -30px;
}
#console #container .prgs .main {
display: block !important;
}
#console #container .prgs .subtext {
display: block !important;
}
#console #container output {
clear: both;
width: 100%;
}
#console #container output h3 {
margin: 0;
}
#console #container output pre {
margin: 0;
}
#console .input-line {
display: -webkit-box;
-webkit-box-orient: horizontal;
-webkit-box-align: stretch;
display: -moz-box;
-moz-box-orient: horizontal;
-moz-box-align: stretch;
display: box;
box-orient: horizontal;
box-align: stretch;
clear: both;
}
#console .input-line > div:nth-child(2) {
-webkit-box-flex: 1;
-moz-box-flex: 1;
box-flex: 1;
}
#console .prompt {
white-space: nowrap;
color: #96b38a;
margin-right: 7px;
display: -webkit-box;
-webkit-box-orient: vertical;
display: -moz-box;
-moz-box-pack: center;
-moz-box-orient: vertical;
display: box;
box-pack: center;
box-orient: vertical;
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
}
#console .cmdline {
outline: none;
background-color: transparent;
margin: 0;
width: 100%;
font: inherit;
padding: 0;
border: 0 !important;
color: inherit;
}
.valid {
outline-color: black !important;
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB