Skip to content
This repository has been archived by the owner on Oct 2, 2023. It is now read-only.

Commit

Permalink
release 0.2.6 (#33)
Browse files Browse the repository at this point in the history
* update to v0.3.0

* add displayResult method in IView

* display each single result found during the for loop in processRecord

* code rev
  • Loading branch information
Raffaello authored Apr 18, 2022
1 parent 2986cab commit 3b2f340
Show file tree
Hide file tree
Showing 11 changed files with 295 additions and 92 deletions.
10 changes: 10 additions & 0 deletions PowerDir.Tests/AbstractViewTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ public string testNames(GetPowerDirInfo info)
{
return names(info);
}

public override void displayResults(IReadOnlyCollection<GetPowerDirInfo> results)
{
throw new NotImplementedException();
}

public override void displayResult(GetPowerDirInfo result)
{
throw new NotImplementedException();
}
}

[DataTestMethod]
Expand Down
98 changes: 56 additions & 42 deletions PowerDir/GetPowerDir.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace PowerDir
public class GetPowerDir : PSCmdlet
{
const int MAX_NAME_LENGTH = 50;
private bool _stop = false;
/*
/// <summary>
/// convert Hex color format to RGB
Expand Down Expand Up @@ -143,9 +144,6 @@ public enum DisplayOptions
public DisplayOptions Display { get; set; } = DisplayOptions.Object;
#endregion Parameters

// TODO: review this HashSet, a concurrent bag maybe btter
private readonly HashSet<GetPowerDirInfo> results = new HashSet<GetPowerDirInfo>();

private bool _supportColor = true;
int _width = 120;
// TODO: consider to use just writeObject generating a string instead as it can support color with ESC[ sequence
Expand All @@ -163,7 +161,8 @@ public enum DisplayOptions

// TODO to be upgraded to 24 bits
private PowerDirTheme theme = new PowerDirTheme();

private IView? view;

#region WriteOps
private void write(string msg)
{
Expand Down Expand Up @@ -232,7 +231,6 @@ private void setColor(PowerDirTheme.ColorThemeItem color)

#endregion


#region Colored WriteOps
//private void write(string msg, int fg, int bg)
//{
Expand Down Expand Up @@ -365,27 +363,6 @@ protected override void BeginProcessing()
// WriteDebug(PagingParameters.ToString());
//}

base.BeginProcessing();
}

/// <summary>
///
/// </summary>
protected override void ProcessRecord()
{
// TODO: consider to process this while displaying instead.
foreach (string dir in Directory.EnumerateDirectories(basePath, Path, enumerationOptions))
{
var dirInfo = new DirectoryInfo(dir);
results.Add(new GetPowerDirInfo(dirInfo, basePath));
}

foreach (string file in Directory.EnumerateFiles(basePath, Path, enumerationOptions))
{
var fileInfo = new FileInfo(file);
results.Add(new GetPowerDirInfo(fileInfo, basePath));
}

switch (Display)
{
case DisplayOptions.Object:
Expand All @@ -403,25 +380,64 @@ protected override void ProcessRecord()
}
}

/// <summary>
///
/// </summary>
protected override void ProcessRecord()
{
// TODO: not sure if it is nice this branch, but don't know how to visualize the directory first,
// unless i am going to implement my recursive method to discover direcories and files with in it.
// at the moment this is the quickest way. I don't want yet to implement my own search recursive method.
if (Recursive)
{
foreach (string fileSys in Directory.EnumerateFileSystemEntries(basePath, Path, enumerationOptions))
{
FileSystemInfo info = Directory.Exists(fileSys) ?
new DirectoryInfo(fileSys) :
new FileInfo(fileSys);

view?.displayResult(new GetPowerDirInfo(info, basePath));
if (_stop)
return;
}
}
else
{
foreach (string dir in Directory.EnumerateDirectories(basePath, Path, enumerationOptions))
{
var dirInfo = new DirectoryInfo(dir);
view?.displayResult(new GetPowerDirInfo(dirInfo, basePath));
if (_stop)
return;
}

foreach (string file in Directory.EnumerateFiles(basePath, Path, enumerationOptions))
{
var fileInfo = new FileInfo(file);
view?.displayResult(new GetPowerDirInfo(fileInfo, basePath));
if (_stop)
return;
}
}
}

private void displayObject()
{
WriteObject(results, true);
view = new DefaultView(WriteObject);
}

private void displayList()
{
var l = new ListView(write, write, writeLine, theme);
l.displayResults(results);
view = new ListView(write, write, writeLine, theme);
}
private void displayListDetails()
{
// TODO
// permissions?
// etc
// TODO switch parameter for dateTime type
ListDetailsView ldv = new ListDetailsView(_width, MAX_NAME_LENGTH,
view = new ListDetailsView(_width, MAX_NAME_LENGTH,
write, write, writeLine, theme, ListDetailsView.EDateTimes.CREATION);
ldv.displayResults(results);
}

private void displayWide()
Expand All @@ -435,27 +451,25 @@ private void displayWide()

WriteDebug($"width = {_width} --- col_size = {col_size} --- num_columns = {num_columns}");

WideView view = new WideView(_width, num_columns, write, write, writeLine, theme);
view.displayResults(results);
view = new WideView(_width, num_columns, write, write, writeLine, theme);
}


/// <summary>
///
/// </summary>
protected override void EndProcessing()
{
results.Clear();
base.EndProcessing();
view?.endDisplay();
}
/*

/// <summary>
///
/// </summary>
//protected override void StopProcessing()
//{
// base.StopProcessing();
//}
*/
protected override void StopProcessing()
{
_stop = true;
view?.endDisplay();
}

}
}
2 changes: 1 addition & 1 deletion PowerDir/PowerDir.GetPowerDir.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'PowerDir.dll'

# Version number of this module.
ModuleVersion = '0.2.5'
ModuleVersion = '0.3.0'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
2 changes: 1 addition & 1 deletion PowerDir/PowerDir.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>0.2.5</Version>
<Version>0.3.0</Version>
<Copyright>(c) BlueRedSky LTD. All rights reserved.</Copyright>
<Authors>Raffaello Bertini</Authors>
<Company>BlueRedSky LTD</Company>
Expand Down
42 changes: 35 additions & 7 deletions PowerDir/PowerDirTheme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ namespace PowerDir
// .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.CPL
// check if PATHEXT is a powershell env variable for executable file
// in case integrate for the extension to highlight
internal class PowerDirTheme
/// <summary>
///
/// </summary>
public class PowerDirTheme
{
const string PATHEXT = "PATHEXT";
/// <summary>
Expand All @@ -31,10 +34,18 @@ enum KeyColorTheme
READONLY_FILE,
ORIGINAL,
}

/// <summary>
///
/// </summary>
public struct ColorThemeItem
{
/// <summary>
///
/// </summary>
public ConsoleColor Fg { get; }
/// <summary>
///
/// </summary>
public ConsoleColor Bg { get; }
internal ColorThemeItem(ConsoleColor fg, ConsoleColor bg)
{
Expand All @@ -43,7 +54,7 @@ internal ColorThemeItem(ConsoleColor fg, ConsoleColor bg)
}
}

Dictionary<KeyColorTheme, ColorThemeItem> colorTheme = new Dictionary<KeyColorTheme, ColorThemeItem>()
readonly Dictionary<KeyColorTheme, ColorThemeItem> colorTheme = new Dictionary<KeyColorTheme, ColorThemeItem>()
{
{KeyColorTheme.DIRECTORY, new ColorThemeItem(ConsoleColor.Blue, ConsoleColor.Black)},
{KeyColorTheme.FILE, new ColorThemeItem(ConsoleColor.Gray, ConsoleColor.Black)},
Expand All @@ -59,7 +70,10 @@ internal ColorThemeItem(ConsoleColor fg, ConsoleColor bg)

internal readonly HashSet<string> _extensions;
private readonly string[] _default_extensions = { ".EXE", ".COM", ".BAT", ".CMD", ".PS1" };

/// <summary>
///
/// </summary>
/// <param name="original_color"></param>
public PowerDirTheme(ColorThemeItem original_color)
{
colorTheme.Add(KeyColorTheme.ORIGINAL, original_color);
Expand All @@ -69,23 +83,37 @@ public PowerDirTheme(ColorThemeItem original_color)
l.AddRange(_default_extensions);
_extensions = new HashSet<string>(l);
}

/// <summary>
///
/// </summary>
/// <param name="original_fg"></param>
/// <param name="original_bg"></param>
public PowerDirTheme(ConsoleColor original_fg, ConsoleColor original_bg) :
this(new ColorThemeItem(original_fg, original_bg))
{
}

// If not supporting color...
/// <summary>
/// If not supporting color
/// </summary>
public PowerDirTheme()
{
colorTheme.Add(KeyColorTheme.ORIGINAL, new ColorThemeItem(ConsoleColor.Gray, ConsoleColor.Black));
_extensions = new HashSet<string>();
}

/// <summary>
///
/// </summary>
/// <returns></returns>
public ColorThemeItem GetOriginalColor()
{
return colorTheme[KeyColorTheme.ORIGINAL];
}
/// <summary>
///
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
public ColorThemeItem GetColor(GetPowerDirInfo info)
{
// TODO review the colors as those are not mutual exclusive
Expand Down
Loading

0 comments on commit 3b2f340

Please sign in to comment.